X-Git-Url: https://git.piment-noir.org/?p=TP_POO.git;a=blobdiff_plain;f=Piles%2FPile.java;h=5d309d16ab415dbc51092813e85c54ddb56a7d66;hp=b82dd7e8f99ff3007d36af587b2ea9a76c3b4033;hb=b5d597d83099c155e21695da51bbefeba72c7dc9;hpb=b48ca56a1f3dd80b09d1840121de5e694a989fb8 diff --git a/Piles/Pile.java b/Piles/Pile.java index b82dd7e..5d309d1 100644 --- a/Piles/Pile.java +++ b/Piles/Pile.java @@ -1,63 +1,109 @@ -class Pile { - private int int_array[]; +/** + * + */ +public class Pile { + private int[] int_array; private int array_size; - private int stack_head_index; + private int head_index; + /** + * [Pile description] + * @param int size [description] + */ + Pile(int size) { + int_array = new int[size]; + setSize(size); + setHeadIndex(0); + } + + /** + * set the size of the internal array + * @param int size the size of the array + */ private void setSize(int size) { array_size = size; } + /** + * get the size of the internal array + * @return the integer size of the internal array + */ private int getSize() { return array_size; } + /** + * set the stack head index + * @param int index the stack head index + */ private void setHeadIndex(int index) { - stack_head_index = index; + head_index = index; } + /** + * get the stack head current index + * @return the integer stack head index + */ private int getHeadIndex() { - return stack_head_index; - } - - Pile(int size) { - int_array = new int[size]; - setSize(size); - setHeadIndex(0); + return head_index; } + /** + * [empiler description] + * @param int value [description] + */ public void empiler(int value) { if (!plein()) { - int_array[stack_head_index] = value; - stack_head_index++; + int_array[head_index] = value; + head_index++; } else { System.out.println("La pile est pleine"); } } + /** + * [depiler description] + * @return [description] + */ public int depiler() { if (!vide()) { - stack_head_index--; - return int_array[stack_head_index]; + head_index--; + return int_array[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++) { + for (int i = 0; i < getHeadIndex(); 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 stack = new Pile(5); @@ -69,19 +115,19 @@ class Pile { 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()); + 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(); }