public class Example { public static void main(String[] args) { Node head = new Node("Chu"); Node p = head; p.next = new Node("Jim"); p = p.next; p.next = new Node("Bill"); display(head); p = head; Node addOne = new Node("will", p.next); p.next = addOne; display(head); } public static void display(Node head) { Node p = head; while(p != null) { System.out.printf("%s => ", p.data); p = p.next; } System.out.println("null"); } } |