class LispList { private Cell myList; private LispList(Cell list) { myList=list; } public boolean isEmpty() { return myList==null; } public E head() { return myList.first; } public LispList tail() { return new LispList(myList.rest); } public LispList cons(E item) { return new LispList(new Cell(item,myList)); } public static LispList empty() { return new LispList(null); } public boolean equals(Object other) { LispList otherList = (LispList) other; if(this.isEmpty()) return otherList.isEmpty(); else return this.head().equals(otherList.head()) && this.tail().equals(otherList.tail()); } public String toString() { if(isEmpty()) return "[]"; else return "["+head()+restToString(tail()); } private static String restToString(LispList l) { if(l.isEmpty()) return "]"; else return ","+l.head()+restToString(l.tail()); } private static class Cell { T first; Cell rest; Cell(T h,Cell t) { first=h; rest=t; } } }