/* * Kyle Pierce * CSE 143 * * Simple program that constructs a short linked list and prints it out */ public class ListExample { public static void main(String[] args) { // This is the version we started with, where we only had the 0-argument // ListNode constructor. We found this tedious, so we added more. // // For seeing in the jGRASP debugger, run this version ListNode list = new ListNode(); list.data = 3; list.next = new ListNode(); list.next.data = 7; list.next.next = new ListNode(); list.next.next.data = 2; list.next.next.next = null; System.out.println(list.data + " " + list.next.data + " " + list.next.next.data); // after writing the constructor ListNode(int data), we can do this. ListNode list2 = new ListNode(3); list2.next = new ListNode(7); list2.next.next = new ListNode(2); System.out.println(list2.data + " " + list.next.data + " " + list2.next.next.data); // with both new constructors, we can write this code ListNode list3 = new ListNode(3, new ListNode(7, new ListNode(2))); System.out.println(list3.data + " " + list3.next.data + " " + list3.next.next.data); } }