public class SinglyLinkedListDemoApp
1: //SinglyLinkedListDemoApp.java
3: public class SinglyLinkedListDemoApp
4: {
5: public static void main(String[] args)
6: {
7: LinkedList numList = new LinkedList();
8: Node nodeA = new Node(66);
9: Node nodeB = new Node(99);
10: Node nodeC = new Node(44);
11: Node nodeD = new Node(95);
12: Node nodeE = new Node(42);
13: Node nodeF = new Node(17);
15: numList.append(nodeB); // Add 99
16: numList.append(nodeC); // Add 44, make the tail
17: numList.append(nodeE); // Add 42, make the tail
19: numList.prepend(nodeA); // Add 66, make the head
21: numList.insertAfter(nodeC, nodeD); // Insert 95 after 44
22: numList.insertAfter(nodeE, nodeF); // Insert 17 after tail (42)
24: // Output list
25: System.out.print("List after adding nodes: ");
26: numList.printList();
28: // Remove the tail node, then the head node
29: numList.removeAfter(nodeE);
30: numList.removeAfter(null);
32: // Output final list
33: System.out.print("List after removing nodes: ");
34: numList.printList();
35: }
36: }