class LinkedList implements List { private Cell myList; LinkedList() { myList=null; } private LinkedList(Cell list) { myList=list; } public boolean isempty() { return myList==null; } public Object head() { return myList.first; } public List tail() { return new LinkedList(myList.rest); } public List cons(Object obj) { return new LinkedList(new Cell(obj,myList)); } public static List empty() { return new LinkedList(null); } public String toString() { if(isempty()) return "[]"; else return "["+head()+restToString(tail()); } private static String restToString(List L) { if(L.isempty()) return "]"; else return ","+L.head()+restToString(L.tail()); } private static class Cell { Object first; Cell rest; Cell(Object h,Cell t) { first=h; rest=t; } } }