Fix the Liste code to not be a linked list of ordered values ...
[TP_POO.git] / Listes / Liste.java
index 6a62aea93ac02feeaba37c34db1421ae8a06750e..6dd1c5fb58abc7194f905d2bda87f75b385b9139 100644 (file)
@@ -37,7 +37,7 @@ class Liste {
     private int list_counter;
 
     Liste() {
-        setheadNode(null);
+        setHeadNode(null);
         setSize(0);
     }
 
@@ -54,43 +54,35 @@ class Liste {
         list_counter = size;
     }
 
-    private void setheadNode(IntNode node) {
+    private void setHeadNode(IntNode node) {
         headNode = node;
     }
 
-    private IntNode getheadNode() {
+    private IntNode getHeadNode() {
         return headNode;
     }
 
     public void inserer(int value) {
-        boolean inserted = false;
+        boolean found = false;
         if (isEmpty()) {
             headNode = new IntNode(value);
             list_counter++;
             return;
-        } else if (value < headNode.getData()) {
-            headNode = new IntNode(value, headNode);
-            list_counter++;
+        } else if (value == headNode.getData()) {
+            found = true;
             return;
         } else {
-            IntNode nodeCursor = headNode;
             IntNode nodeCursorNext = headNode.getNext();
             while (nodeCursorNext != null) {
-                if (value == nodeCursor.getData() || value == nodeCursorNext.getData()) {
-                    inserted = true;
-                    break;
-                } else if (value > nodeCursor.getData() && value < nodeCursorNext.getData()) {
-                    nodeCursor.setNext(new IntNode(value, nodeCursorNext));
-                    inserted = true;
-                    list_counter++;
+                if (value == nodeCursorNext.getData()) {
+                    found = true;
                     break;
                 } else {
-                    nodeCursor = nodeCursorNext;
                     nodeCursorNext = nodeCursorNext.getNext();
                 }
             }
-            if (!inserted) {
-                nodeCursor.setNext(new IntNode(value));
+            if (!found) {
+                headNode = new IntNode(value, headNode);
                 list_counter++;
             }
         }