X-Git-Url: https://git.piment-noir.org/?p=Project_POO.git;a=blobdiff_plain;f=exo4%2FListe.java;fp=exo4%2FListe.java;h=abf2efd58ac91f824e8930f949c8238b633c72db;hp=6928b00737e0656548f61f6b49cc791812f80b77;hb=bb6a4f9a6e8fe7d7a6a08f008c63072ff2c2e460;hpb=f1809579c7e4fe66338985cc6f8e9e5c2399cf0e diff --git a/exo4/Liste.java b/exo4/Liste.java index 6928b00..abf2efd 100644 --- a/exo4/Liste.java +++ b/exo4/Liste.java @@ -4,40 +4,7 @@ date = "05/12/2011" ) 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() { @@ -58,25 +25,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; @@ -86,7 +53,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 @@ -103,8 +70,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()); @@ -129,7 +96,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) { @@ -148,7 +115,7 @@ public class Liste extends Structure { headNode = null; } else { // We have at least 2 nodes in the linked list - IntNode nodeCursor = headNode; + Node nodeCursor = headNode; int i = 0; // Go to the node at the nElements place while (i < nElements - 1 && nodeCursor.getNext() != null && nElements > 1) {