/** ListNode is a class used internally by the List class. Each node in a List is represented as a ListNode, with an item and a reference to the next node in the list. */ class ListNode { public Object item; public ListNode next; /** Postcondition: Construct a ListNode with item i and * next null. */ ListNode(Object obj) { item = obj; next = null; } /** Postcondition: Construct a ListNode with item i and * next n. */ ListNode(Object obj, ListNode n) { item = obj; next = n; } /** Precondition: this list is acyclic * Postcondition: Returns a reference to the node at * the given position. If position < 1 or position > the * size number of nodes in the list, returns null. */ public ListNode ptrTo (int position) { if (position < 1) { return null; } else if (position == 1) { return this; } else if (next == null) { return null; } else { return next.ptrTo(position-1); } } }