X-Git-Url: https://git.piment-noir.org/?p=TP_POO.git;a=blobdiff_plain;f=Structure%2FListe.java;fp=Structure%2FListe.java;h=046267e6b211a385d1275071dcec81b690215d27;hp=448878f8c63d4eea071132881798b8ab1233bd94;hb=4d9f4a5860c2dffb988982e330039d09874e22d5;hpb=f00e7dee9b1470315e6365e3d17bf8bbc9aab89e diff --git a/Structure/Liste.java b/Structure/Liste.java index 448878f..046267e 100644 --- a/Structure/Liste.java +++ b/Structure/Liste.java @@ -1,40 +1,7 @@ public class Liste extends Structure { - - private class IntNode { - private int data; - private IntNode next; - - IntNode(int value) { - setData(value); - setNext(null); - } - - IntNode(int value, IntNode nextNode) { - setData(value); - setNext(nextNode); - } - - public int getData() { - return data; - } - - public void setData(int value) { - data = value; - } - - public IntNode getNext() { - return next; - } - - public void setNext(IntNode nextNode) { - next = nextNode; - } - - } - - private IntNode headNode; + private Node headNode; private int list_counter; Liste() { @@ -55,25 +22,25 @@ public class Liste extends Structure { list_counter = size; } - public void setHeadNode(IntNode node) { + public void setHeadNode(Node node) { headNode = node; } - public IntNode getHeadNode() { + public Node getHeadNode() { return headNode; } public boolean inserer(int value) { boolean found = false; if (isEmpty()) { - headNode = new IntNode(value); + headNode = new Node(value); list_counter++; return true; } else if (value == headNode.getData()) { found = true; return true; } else { - IntNode nodeCursorNext = headNode.getNext(); + Node nodeCursorNext = headNode.getNext(); while (nodeCursorNext != null) { if (value == nodeCursorNext.getData()) { found = true; @@ -83,7 +50,7 @@ public class Liste extends Structure { } } if (!found) { - headNode = new IntNode(value, headNode); + headNode = new Node(value, headNode); list_counter++; } // Insertion in a linked list can't fail @@ -100,8 +67,8 @@ public class Liste extends Structure { deleted = true; list_counter--; } else { - IntNode nodeCursor = headNode; - IntNode nodeCursorNext = headNode.getNext(); + Node nodeCursor = headNode; + Node nodeCursorNext = headNode.getNext(); while (nodeCursorNext != null) { if (value == nodeCursorNext.getData()) { nodeCursor.setNext(nodeCursorNext.getNext()); @@ -126,7 +93,7 @@ public class Liste extends Structure { } else if (headNode.getNext() == null) { System.out.println("element " + i + " : " + headNode.getData()); } else { - IntNode nodeCursorNext = headNode.getNext(); + Node nodeCursorNext = headNode.getNext(); System.out.println("element " + i + " : " + headNode.getData()); i++; while (nodeCursorNext != null) {