exo1: Add the ArrayDeque test code.
[Project_POO.git] / exo1 / Main.java
CommitLineData
f695f960
JB
1import java.util.ArrayDeque;
2import java.util.NoSuchElementException;
f5d81de2
JB
3
4class Main {
5
6 /**
7 * The main() function
8 * @param String[] args main() function arguments array
9 */
10 public static void main(String[] args) {
11 Pile<Integer> stack = new Pile<Integer>(5);
12
13 stack.empiler(3);
14 stack.empiler(5);
15 stack.empiler(4);
16 stack.empiler(7);
17 stack.empiler(8);
18
19 stack.afficher();
20
21 System.out.println("Stack index " + stack.getHeadIndex());
22 System.out.println("Stack head value " + stack.depiler());
23 System.out.println("Stack index " + stack.getHeadIndex());
24 System.out.println("Stack head value " + stack.depiler());
25 System.out.println("Stack index " + stack.getHeadIndex());
26 System.out.println("Stack head value " + stack.depiler());
27 System.out.println("Stack index " + stack.getHeadIndex());
28 System.out.println("Stack head value " + stack.depiler());
29 System.out.println("Stack index " + stack.getHeadIndex());
30 System.out.println("Stack head value " + stack.depiler());
31 System.out.println("Stack index " + stack.getHeadIndex());
32 System.out.println("Stack head value " + stack.depiler());
33 System.out.println("Stack index " + stack.getHeadIndex());
34
35 stack.afficher();
36
37 Pile<String> stackStr = new Pile<String>(5);
38
39 stackStr.empiler("Bonjour");
40 stackStr.empiler("Salut");
41 stackStr.empiler("Hello");
42 stackStr.empiler("Hi");
43 stackStr.empiler("Hugh");
44
45 stackStr.afficher();
46
47 System.out.println("Stack index " + stackStr.getHeadIndex());
48 System.out.println("Stack head value " + stackStr.depiler());
49 System.out.println("Stack index " + stackStr.getHeadIndex());
50 System.out.println("Stack head value " + stackStr.depiler());
51 System.out.println("Stack index " + stackStr.getHeadIndex());
52 System.out.println("Stack head value " + stackStr.depiler());
53 System.out.println("Stack index " + stackStr.getHeadIndex());
54 System.out.println("Stack head value " + stackStr.depiler());
55 System.out.println("Stack index " + stackStr.getHeadIndex());
56 System.out.println("Stack head value " + stackStr.depiler());
57 System.out.println("Stack index " + stackStr.getHeadIndex());
58 System.out.println("Stack head value " + stackStr.depiler());
59 System.out.println("Stack index " + stackStr.getHeadIndex());
60
61 stackStr.afficher();
62
63 ArrayDeque<String> stackStrDeq = new ArrayDeque<String>();
64 stackStrDeq.push("Bonjour");
65 stackStrDeq.push("Salut");
66 stackStrDeq.push("Hello");
67 stackStrDeq.push("Hi");
68 stackStrDeq.push("Hugh");
69
f695f960
JB
70 try {
71 System.out.println("Stack index " + stackStrDeq.size());
72 System.out.println("Stack head value " + stackStrDeq.pop());
73 System.out.println("Stack index " + stackStrDeq.size());
74 System.out.println("Stack head value " + stackStrDeq.pop());
75 System.out.println("Stack index " + stackStrDeq.size());
76 System.out.println("Stack head value " + stackStrDeq.pop());
77 System.out.println("Stack index " + stackStrDeq.size());
78 System.out.println("Stack head value " + stackStrDeq.pop());
79 System.out.println("Stack index " + stackStrDeq.size());
80 System.out.println("Stack head value " + stackStrDeq.pop());
81 System.out.println("Stack index " + stackStrDeq.size());
82 // It will trigger the exception
83 System.out.println("Stack head value " + stackStrDeq.pop());
84 System.out.println("Stack index " + stackStrDeq.size());
85 }
86 catch (NoSuchElementException e) {
87 e.printStackTrace();
88 }
f5d81de2
JB
89 }
90}