1 import java
.lang
.reflect
.Array
;
8 private int array_size
;
9 private int stack_head_index
;
12 * set the size of the internal array
13 * @param int size the size of the array
15 public void setSize(int size
) {
20 * get the size of the internal array
21 * @return the integer size of the internal array
23 public int getSize() {
28 * set the stack head index
29 * @param int index the stack head index
31 public void setHeadIndex(int index
) {
32 stack_head_index
= index
;
36 * get the stack head current index
37 * @return the integer stack head index
39 private int getHeadIndex() {
40 return stack_head_index
;
45 * @param int size [description]
47 @SuppressWarnings("unchecked")
49 array
= (E
[])new Object
[size
];
56 * @param int size [description]
58 @SuppressWarnings("unchecked")
59 Pile(Class
<E
[]> cl
, int size
) {
60 array
= (E
[])Array
.newInstance(cl
, size
);
66 * [empiler description]
67 * @param int value [description]
69 public void empiler(E value
) {
71 array
[stack_head_index
] = value
;
74 System
.out
.println("La pile est pleine");
79 * [depiler description]
80 * @return [description]
85 return array
[stack_head_index
];
93 * @return [description]
95 private boolean plein() {
96 return (getHeadIndex() >= getSize());
101 * @return [description]
103 private boolean vide() {
104 return (getHeadIndex() == 0);
108 * [afficher description]
110 public void afficher() {
111 for (int i
= 0; i
< getHeadIndex(); i
++) {
112 System
.out
.println("element " + i
+ " " + array
[i
]);
117 * The main() function
118 * @param String[] args main() function arguments array
120 public static void main(String
[] args
) {
121 Pile
<Integer
> stack
= new Pile
<Integer
>(5);
131 System
.out
.println("Stack index " + stack
.getHeadIndex());
132 System
.out
.println("Stack head value " + stack
.depiler());
133 System
.out
.println("Stack index " + stack
.getHeadIndex());
134 System
.out
.println("Stack head value " + stack
.depiler());
135 System
.out
.println("Stack index " + stack
.getHeadIndex());
136 System
.out
.println("Stack head value " + stack
.depiler());
137 System
.out
.println("Stack index " + stack
.getHeadIndex());
138 System
.out
.println("Stack head value " + stack
.depiler());
139 System
.out
.println("Stack index " + stack
.getHeadIndex());
140 System
.out
.println("Stack head value " + stack
.depiler());
141 System
.out
.println("Stack index " + stack
.getHeadIndex());
142 System
.out
.println("Stack head value " + stack
.depiler());
143 System
.out
.println("Stack index " + stack
.getHeadIndex());
147 Pile
<String
> stackStr
= new Pile
<String
>(5);
149 stackStr
.empiler("Bonjour");
150 stackStr
.empiler("Salut");
151 stackStr
.empiler("Hello");
152 stackStr
.empiler("Hi");
153 stackStr
.empiler("Hugh");
157 System
.out
.println("Stack index " + stackStr
.getHeadIndex());
158 System
.out
.println("Stack head value " + stackStr
.depiler());
159 System
.out
.println("Stack index " + stackStr
.getHeadIndex());
160 System
.out
.println("Stack head value " + stackStr
.depiler());
161 System
.out
.println("Stack index " + stackStr
.getHeadIndex());
162 System
.out
.println("Stack head value " + stackStr
.depiler());
163 System
.out
.println("Stack index " + stackStr
.getHeadIndex());
164 System
.out
.println("Stack head value " + stackStr
.depiler());
165 System
.out
.println("Stack index " + stackStr
.getHeadIndex());
166 System
.out
.println("Stack head value " + stackStr
.depiler());
167 System
.out
.println("Stack index " + stackStr
.getHeadIndex());
168 System
.out
.println("Stack head value " + stackStr
.depiler());
169 System
.out
.println("Stack index " + stackStr
.getHeadIndex());