X-Git-Url: https://git.piment-noir.org/?p=TP_POO.git;a=blobdiff_plain;f=Listes%2FListe.java;h=6dd1c5fb58abc7194f905d2bda87f75b385b9139;hp=6a62aea93ac02feeaba37c34db1421ae8a06750e;hb=684b6099df9f03c36286252a07272358a98c9091;hpb=f1af410600beae0521ecd4abe9439a324ab2250f diff --git a/Listes/Liste.java b/Listes/Liste.java index 6a62aea..6dd1c5f 100644 --- a/Listes/Liste.java +++ b/Listes/Liste.java @@ -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++; } }