/** * A collection built on an list and returning a MyIterator subclass. * * @author R. P. Futrelle * @version 20 June 2003 (started 19 June 2003) */ class MyListCollection { ListCell top, last; // Tested this class using main(), w/o iterator public static void main(String[] args){ MyListCollection mine = new MyListCollection(); mine.add("string1"); mine.add("string2"); System.out.println(mine.top.contents); System.out.println(mine.top.next.contents); } // main() MyListCollection() { init(); } void init() { top = null; last = null; } // init() MyIterator iterator() { return new MyListIterator(this); } boolean add(Object obj) { ListCell cell = new ListCell(obj); if(top == null) { top = cell; last = cell; // skip this? } else last.next = cell; last = cell; return true; } void clear() { init(); } } // MyListCollection class ListCell { Object contents; ListCell next; ListCell (Object item) { contents = item; next = null; } // ListCell() } // class List