X-Git-Url: https://git.piment-noir.org/?p=TP_POO.git;a=blobdiff_plain;f=Piles%2FPile.java;h=565432498d47f40d52ead6fe175e57bb81fcb85a;hp=e7d4b4deac667aa2c934567be2bd81e94d840c3f;hb=9b4b86b9cd28faed5698cf9a5949a89f0088c159;hpb=d3d2d15cbc23943aa4bd255cfa85dad9c4cf5609 diff --git a/Piles/Pile.java b/Piles/Pile.java index e7d4b4d..5654324 100644 --- a/Piles/Pile.java +++ b/Piles/Pile.java @@ -1,88 +1,134 @@ -class Pile { +/** + * + */ +public class Pile { private int int_array[]; private int array_size; - private int heap_head_index; + private int stack_head_index; + /** + * [setSize description] + * @param int size [description] + */ private void setSize(int size) { array_size = size; } + /** + * [getSize description] + * @return [description] + */ private int getSize() { return array_size; } + /** + * [setHeadIndex description] + * @param int index [description] + */ private void setHeadIndex(int index) { - heap_head_index = index; + stack_head_index = index; } + /** + * [getHeadIndex description] + * @return [description] + */ private int getHeadIndex() { - return heap_head_index; + return stack_head_index; } + /** + * [Pile description] + * @param int size [description] + */ Pile(int size) { int_array = new int[size]; setSize(size); setHeadIndex(0); } + /** + * [empiler description] + * @param int value [description] + */ public void empiler(int value) { if (!plein()) { - int_array[heap_head_index] = value; - heap_head_index++; + int_array[stack_head_index] = value; + stack_head_index++; } else { System.out.println("La pile est pleine"); } } + /** + * [depiler description] + * @return [description] + */ public int depiler() { if (!vide()) { - heap_head_index--; - return int_array[heap_head_index]; + stack_head_index--; + return int_array[stack_head_index]; } else { return -1; } } - public boolean plein() { + /** + * [plein description] + * @return [description] + */ + private boolean plein() { return (getHeadIndex() >= getSize()); } - public boolean vide() { + /** + * [vide description] + * @return [description] + */ + private boolean vide() { return (getHeadIndex() == 0); } + /** + * [afficher description] + */ public void afficher() { for (int i = 0; i < getSize(); i++) { System.out.println("element " + i + " " + int_array[i]); } } + /** + * The main() function + * @param String[] args main() function arguments array + */ public static void main(String[] args) { - Pile heap = new Pile(5); - - heap.empiler(3); - heap.empiler(5); - heap.empiler(4); - heap.empiler(7); - heap.empiler(8); - - heap.afficher(); - - System.out.println("Heap index " + heap.getHeadIndex()); - System.out.println("Heap head value " + heap.depiler()); - System.out.println("Heap index " + heap.getHeadIndex()); - System.out.println("Heap head value " + heap.depiler()); - System.out.println("Heap index " + heap.getHeadIndex()); - System.out.println("Heap head value " + heap.depiler()); - System.out.println("Heap index " + heap.getHeadIndex()); - System.out.println("Heap head value " + heap.depiler()); - System.out.println("Heap index " + heap.getHeadIndex()); - System.out.println("Heap head value " + heap.depiler()); - System.out.println("Heap index " + heap.getHeadIndex()); - System.out.println("Heap head value " + heap.depiler()); - System.out.println("Heap index " + heap.getHeadIndex()); - - heap.afficher(); + Pile stack = new Pile(5); + + stack.empiler(3); + stack.empiler(5); + stack.empiler(4); + stack.empiler(7); + stack.empiler(8); + + stack.afficher(); + + System.out.println("Stack index " + stack.getHeadIndex()); + System.out.println("Stack head value " + stack.depiler()); + System.out.println("Stack index " + stack.getHeadIndex()); + System.out.println("Stack head value " + stack.depiler()); + System.out.println("Stack index " + stack.getHeadIndex()); + System.out.println("Stack head value " + stack.depiler()); + System.out.println("Stack index " + stack.getHeadIndex()); + System.out.println("Stack head value " + stack.depiler()); + System.out.println("Stack index " + stack.getHeadIndex()); + System.out.println("Stack head value " + stack.depiler()); + System.out.println("Stack index " + stack.getHeadIndex()); + System.out.println("Stack head value " + stack.depiler()); + System.out.println("Stack index " + stack.getHeadIndex()); + + stack.afficher(); } }