From f00e7dee9b1470315e6365e3d17bf8bbc9aab89e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 4 May 2018 11:10:03 +0200 Subject: [PATCH] Create a generic Node class and make use of it. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- Listes/Liste.java | 51 +++++++++-------------------------------------- Listes/Makefile | 3 ++- 2 files changed, 11 insertions(+), 43 deletions(-) diff --git a/Listes/Liste.java b/Listes/Liste.java index ca2d42d..8256bcb 100644 --- a/Listes/Liste.java +++ b/Listes/Liste.java @@ -1,40 +1,7 @@ public class Liste { - - 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); - } - - private int getData() { - return data; - } - - private void setData(int value) { - data = value; - } - - private IntNode getNext() { - return next; - } - - private void setNext(IntNode nextNode) { - next = nextNode; - } - - } - - private IntNode headNode; + private Node headNode; private int list_counter; Liste() { @@ -55,25 +22,25 @@ public class Liste { list_counter = size; } - private void setHeadNode(IntNode node) { + private void setHeadNode(Node node) { headNode = node; } - private IntNode getHeadNode() { + private Node getHeadNode() { return headNode; } public void inserer(int value) { boolean found = false; if (isEmpty()) { - headNode = new IntNode(value); + headNode = new Node(value); list_counter++; return; } else if (value == headNode.getData()) { found = true; return; } 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 { } } if (!found) { - headNode = new IntNode(value, headNode); + headNode = new Node(value, headNode); list_counter++; } } @@ -98,8 +65,8 @@ public class Liste { 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()); @@ -124,7 +91,7 @@ public class Liste { } 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) { diff --git a/Listes/Makefile b/Listes/Makefile index 0b2363e..6d4086d 100644 --- a/Listes/Makefile +++ b/Listes/Makefile @@ -46,7 +46,8 @@ JVM = java # NAME = Camilo Juan CLASSES = \ - Liste.java + Node.java \ + Liste.java # # MAIN is a variable with the name of the file containing the main method -- 2.34.1