public class List { private ListNode myHead; public List ( ) { myHead = null; } public boolean isEmpty ( ) { return myHead == null; } private static class ListNode { private Object myFirst; private ListNode myRest; private ListNode (Object first, ListNode rest) { myFirst = first; myRest = rest; } private ListNode (Object first) { myFirst = first; myRest = null; } } public String toString ( ) { String rtn = "( "; for (ListNode p = myHead; p != null; p = p.myRest) { rtn = rtn + p.myFirst + " "; } return rtn + ")"; } // Return the number of items in this list ("length" in Scheme). public int size ( ) { int rtn = 0; for (ListNode p = myHead; p != null; p = p.myRest) { rtn++; } return rtn; } // Return a reference to the sublist of this list that begins // with the given element; returns the empty list if this list // doesn't contain the given element. public boolean contains (Object obj) { for (ListNode p = myHead; p != null; p = p.myRest) { if (obj.equals (p.myFirst)) { return true; } } return false; } // Returns the element at the given position in this list. public Object get (int pos) { if (pos < 0) { throw new IllegalArgumentException ( "Argument to get must be at least 0."); } if (pos >= size ( )) { throw new IllegalArgumentException ("Argument to get is too large."); } int k = 0; for (ListNode p = myHead; p != null; p = p.myRest) { if (k == pos) { return p.myFirst; } k++; } return null; } public void addToFront (Object obj) { myHead = new ListNode (obj, myHead); } public boolean equals (Object obj) { // to be supplied } public void add (Object x) { // to be supplied } public void appendInPlace (List l) { // to be supplied } }