// Hunter Schafer, CSE 143 // An example client of ListNodes public class ListNodeClient { public static void main(String[] args) { // This is only to make the jGRASP debugger look nice ListNode dummy = new ListNode(-1); // Want to make the list 42 -> -3 -> 17 -> 9 // Original version // ListNode list = new ListNode(); // list.data = 42; // list.next = new ListNode(); // list.next.data = -3; // list.next.next = new ListNode(); // list.next.next.data = 17; // list.next.next.next = new ListNode(); // list.next.next.next.data = 9; // Shorter version ListNode list = new ListNode(42, new ListNode(-3, new ListNode(17, new ListNode(9)))); // System.out.println(list.data); // System.out.println(list.next.data); // System.out.println(list.next.next.data); // System.out.println(list.next.next.next.data); ListNode current = list; while (current != null) { System.out.println(current.data); current = current.next; } } }