1class Node {
2 Object data;
3 Node next;
4 Node(Object d,Node n) {
5 data = d ;
6 next = n ;
7 }
8
9 public static Node addLast(Node header, Object x) {
10 // save the reference to the header so we can return it.
11 Node ret = header;
12
13 // check base case, header is null.
14 if (header == null) {
15 return new Node(x, null);
16 }
17
18 // loop until we find the end of the list
19 while ((header.next != null)) {
20 header = header.next;
21 }
22
23 // set the new node to the Object x, next will be null.
24 header.next = new Node(x, null);
25 return ret;
26 }
27}