/** ListNode is a class for storing a single node of a linked list that stores int values. * It stores an integer value and a link to the next node of the linked list. */ public class ListNode { int data; ListNode next; /** Creates a terminal ListNode with 0 as its data. */ public ListNode() { this(0, null); } /** Creates a terminal ListNode with data as its data. */ public ListNode(int data) { this(data, null); } /** Creates a ListNode with data as its data and next as the node it points to. */ public ListNode(int data, ListNode next) { this.data = data; this.next = next; } /* Ignore this for now */ public String toString() { String result = "["; ListNode current = this; while (current.next != null) { result += current.data + ", "; current = current.next; } while (current != null) { result += current.data; current = current.next; } return result + "]"; } }