--- /dev/null
+public class Node<T> {
+ private T data;
+ private Node<T> next;
+
+ Node(T value) {
+ setData(value);
+ setNext(null);
+ }
+
+ Node(T value, Node<T> nextNode) {
+ setData(value);
+ setNext(nextNode);
+ }
+
+ public T getData() {
+ return data;
+ }
+
+ public void setData(T value) {
+ data = value;
+ }
+
+ public Node<T> getNext() {
+ return next;
+ }
+
+ public void setNext(Node<T> nextNode) {
+ next = nextNode;
+ }
+
+}
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<Integer> headNode;
private int list_counter;
Liste() {
list_counter = size;
}
- public void setHeadNode(IntNode node) {
+ public void setHeadNode(Node<Integer> node) {
headNode = node;
}
- public IntNode getHeadNode() {
+ public Node<Integer> getHeadNode() {
return headNode;
}
public boolean inserer(int value) {
boolean found = false;
if (isEmpty()) {
- headNode = new IntNode(value);
+ headNode = new Node<Integer>(value);
list_counter++;
return true;
} else if (value == headNode.getData()) {
found = true;
return true;
} else {
- IntNode nodeCursorNext = headNode.getNext();
+ Node<Integer> nodeCursorNext = headNode.getNext();
while (nodeCursorNext != null) {
if (value == nodeCursorNext.getData()) {
found = true;
}
}
if (!found) {
- headNode = new IntNode(value, headNode);
+ headNode = new Node<Integer>(value, headNode);
list_counter++;
}
// Insertion in a linked list can't fail
deleted = true;
list_counter--;
} else {
- IntNode nodeCursor = headNode;
- IntNode nodeCursorNext = headNode.getNext();
+ Node<Integer> nodeCursor = headNode;
+ Node<Integer> nodeCursorNext = headNode.getNext();
while (nodeCursorNext != null) {
if (value == nodeCursorNext.getData()) {
nodeCursor.setNext(nodeCursorNext.getNext());
} else if (headNode.getNext() == null) {
System.out.println("element " + i + " : " + headNode.getData());
} else {
- IntNode nodeCursorNext = headNode.getNext();
+ Node<Integer> nodeCursorNext = headNode.getNext();
System.out.println("element " + i + " : " + headNode.getData());
i++;
while (nodeCursorNext != null) {
CLASSES = \
Structure.java \
- Entiers.java \
+ Entiers.java \
+ Node.java \
Liste.java \
Main.java
--- /dev/null
+public class Node<T> {
+ private T data;
+ private Node<T> next;
+
+ Node(T value) {
+ setData(value);
+ setNext(null);
+ }
+
+ Node(T value, Node<T> nextNode) {
+ setData(value);
+ setNext(nextNode);
+ }
+
+ public T getData() {
+ return data;
+ }
+
+ public void setData(T value) {
+ data = value;
+ }
+
+ public Node<T> getNext() {
+ return next;
+ }
+
+ public void setNext(Node<T> nextNode) {
+ next = nextNode;
+ }
+
+}
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<Integer> headNode;
private int list_counter;
Liste() {
list_counter = size;
}
- public void setHeadNode(IntNode node) {
+ public void setHeadNode(Node<Integer> node) {
headNode = node;
}
- public IntNode getHeadNode() {
+ public Node<Integer> getHeadNode() {
return headNode;
}
public boolean inserer(int value) {
boolean found = false;
if (isEmpty()) {
- headNode = new IntNode(value);
+ headNode = new Node<Integer>(value);
list_counter++;
return true;
} else if (value == headNode.getData()) {
found = true;
return true;
} else {
- IntNode nodeCursorNext = headNode.getNext();
+ Node<Integer> nodeCursorNext = headNode.getNext();
while (nodeCursorNext != null) {
if (value == nodeCursorNext.getData()) {
found = true;
}
}
if (!found) {
- headNode = new IntNode(value, headNode);
+ headNode = new Node<Integer>(value, headNode);
list_counter++;
}
// Insertion in a linked list can't fail
deleted = true;
list_counter--;
} else {
- IntNode nodeCursor = headNode;
- IntNode nodeCursorNext = headNode.getNext();
+ Node<Integer> nodeCursor = headNode;
+ Node<Integer> nodeCursorNext = headNode.getNext();
while (nodeCursorNext != null) {
if (value == nodeCursorNext.getData()) {
nodeCursor.setNext(nodeCursorNext.getNext());
} else if (headNode.getNext() == null) {
System.out.println("element " + i + " : " + headNode.getData());
} else {
- IntNode nodeCursorNext = headNode.getNext();
+ Node<Integer> nodeCursorNext = headNode.getNext();
System.out.println("element " + i + " : " + headNode.getData());
i++;
while (nodeCursorNext != null) {
headNode = null;
} else {
// We have at least 2 nodes in the linked list
- IntNode nodeCursor = headNode;
+ Node<Integer> nodeCursor = headNode;
int i = 0;
// Go to the node at the nElements place
while (i < nElements - 1 && nodeCursor.getNext() != null && nElements > 1) {
Segment.java \
Cercle.java \
Entiers.java \
+ Node.java \
Liste.java \
Piletransformations.java \
Main.java
--- /dev/null
+public class Node<T> {
+ private T data;
+ private Node<T> next;
+
+ Node(T value) {
+ setData(value);
+ setNext(null);
+ }
+
+ Node(T value, Node<T> nextNode) {
+ setData(value);
+ setNext(nextNode);
+ }
+
+ public T getData() {
+ return data;
+ }
+
+ public void setData(T value) {
+ data = value;
+ }
+
+ public Node<T> getNext() {
+ return next;
+ }
+
+ public void setNext(Node<T> nextNode) {
+ next = nextNode;
+ }
+
+}