X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=exo1%2FPile.java;h=91bd51087ed95e3b7e253f7cc858d77514a66828;hb=f1809579c7e4fe66338985cc6f8e9e5c2399cf0e;hp=74998e44a976cc02048fab22ae29cf49998bb993;hpb=6392c37e53120c8a5f8fa62588c21a60940c1d1f;p=Project_POO.git diff --git a/exo1/Pile.java b/exo1/Pile.java index 74998e4..91bd510 100644 --- a/exo1/Pile.java +++ b/exo1/Pile.java @@ -6,7 +6,7 @@ import java.lang.reflect.Array; public class Pile { private E[] array; private int array_size; - private int stack_head_index; + private int head_index; /** * set the size of the internal array @@ -29,15 +29,15 @@ public class Pile { * @param int index the stack head index */ public 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; + public int getHeadIndex() { + return head_index; } /** @@ -68,8 +68,8 @@ public class Pile { */ public void empiler(E value) { if (!plein()) { - array[stack_head_index] = value; - stack_head_index++; + array[head_index] = value; + head_index++; } else { System.out.println("La pile est pleine"); } @@ -81,8 +81,8 @@ public class Pile { */ public E depiler() { if (!vide()) { - stack_head_index--; - return array[stack_head_index]; + head_index--; + return array[head_index]; } else { return null; } @@ -113,61 +113,4 @@ public class Pile { } } - /** - * The main() function - * @param String[] args main() function arguments array - */ - public static void main(String[] args) { - 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(); - - Pile stackStr = new Pile(5); - - stackStr.empiler("Bonjour"); - stackStr.empiler("Salut"); - stackStr.empiler("Hello"); - stackStr.empiler("Hi"); - stackStr.empiler("Hugh"); - - stackStr.afficher(); - - System.out.println("Stack index " + stackStr.getHeadIndex()); - System.out.println("Stack head value " + stackStr.depiler()); - System.out.println("Stack index " + stackStr.getHeadIndex()); - System.out.println("Stack head value " + stackStr.depiler()); - System.out.println("Stack index " + stackStr.getHeadIndex()); - System.out.println("Stack head value " + stackStr.depiler()); - System.out.println("Stack index " + stackStr.getHeadIndex()); - System.out.println("Stack head value " + stackStr.depiler()); - System.out.println("Stack index " + stackStr.getHeadIndex()); - System.out.println("Stack head value " + stackStr.depiler()); - System.out.println("Stack index " + stackStr.getHeadIndex()); - System.out.println("Stack head value " + stackStr.depiler()); - System.out.println("Stack index " + stackStr.getHeadIndex()); - - stackStr.afficher(); - } }