public class TestListNode
1: //TestListNode.java
2:
3: public class TestListNode
4: {
5: public static void main(String[] args)
6: {
7: //Create a list containing A, B, C in that order.
8: ListNode head = new ListNode();
9: head.setData("A");
10: ListNode tail = head;
11: tail.setLink(new ListNode("B", null));
12: tail = tail.getLink();
13: tail.setLink(new ListNode("C", null));
14: tail = tail.getLink();
15: //Now add to the end nodes cotaining
16: //D, E, F, G, H, I, and J, in that order.
17: for (int i = 1; i <= 7; i++)
18: {
19: String newString = "" + (char)(tail.getData().charAt(0) + 1);
20: tail.setLink(new ListNode(newString, null));
21: tail = tail.getLink();
22: }
23:
24: /*
25: //Now remove nodes containing E, F and G.
26: ListNode nodePointer = head;
27: while (!nodePointer.getData().equals("D"))
28: {
29: nodePointer = nodePointer.getLink();
30: }
31: for (int i = 1; i <= 3; i++)
32: {
33: nodePointer.setLink(nodePointer.getLink().getLink());
34: }
35: */
36:
37: ListNode currentNode = head;
38: while (currentNode != null)
39: {
40: System.out.println(currentNode.getData());
41: currentNode = currentNode.getLink();
42: }
43: }
44: }
45: