Les listes – vidéo d’explication

Le code final montré au début de la vidéo

class Node {
	String item;
	Node next = null;

	Node(String i) {
		item = i;
	}
}

Node n1 = new Node("Tokyo");
Node n2 = new Node("Paris");
Node n3 = new Node("Rome");

n1.next = n2;
n2.next = n3;
n3.next = null;

Node head = n1;

Node tmp = head;

while (tmp != null) {
	System.out.println(tmp.item);
	tmp = tmp.next;
}

Node n4 = new Node("Manilla");
n4.next = head.next;
head.next = n4;

// Display the result
tmp = head;

System.out.println("\nInsertion of Manilla");
while (tmp != null) {
	System.out.println(tmp.item);
	tmp = tmp.next;
}