TP2: cast double to int the compare method returned value.
[TP_POO.git] / TP2 / Entiers.java
index b4cffb15f6f90406be47212e9f9dede7a02f1e66..b690d10426728590f0efa8365a448f1cd531baa6 100644 (file)
@@ -60,7 +60,7 @@ class Entiers extends Structure {
 
     private int binarySearch(int first, int last, int value) {
         if (last < first)
-            //FIXME: should not return an integer 
+            //FIXME: should not return an integer
             return -1;
         int middle = (first + last) / 2;
         if (value == int_array[middle])
@@ -75,7 +75,6 @@ class Entiers extends Structure {
             System.out.println("Aucune valeur à supprimer");
             return false;
         }
-
         for (int i = 0; i < getCurrentSize(); i++) {
             if (int_array[i] == value) {
                 // Deleting the element in the tab
@@ -98,10 +97,20 @@ class Entiers extends Structure {
     }
 
     public void afficher() {
-        System.out.println("---- entiers ----");
+        String className = this.getClass().getSimpleName();
+        System.out.println("---- " + className + " ----");
         for (int i = 0; i < getCurrentSize(); i++) {
             System.out.println("element " + i + " : " + int_array[i]);
         }
     }
 
+    public void compacter(int nElements) {
+        if (current_size - nElements > 0) {
+            // Remove the last nElements
+            current_size -= nElements;
+        } else {
+            current_size = 0;
+        }
+    }
+
 }