From: Jérôme Benoit Date: Fri, 9 Feb 2018 09:04:57 +0000 (+0100) Subject: Fix the Liste code to not be a linked list of ordered values ... X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=684b6099df9f03c36286252a07272358a98c9091;p=TP_POO.git Fix the Liste code to not be a linked list of ordered values ... Signed-off-by: Jérôme Benoit --- diff --git a/Listes/Liste.java b/Listes/Liste.java index 3b03590..6dd1c5f 100644 --- a/Listes/Liste.java +++ b/Listes/Liste.java @@ -63,34 +63,26 @@ class Liste { } 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++; } }