class orderedlist {
Comparator comparator;
OrderedList(Comparator c) {
this.comparator = c;
}
int indexOf(Object o);
Object get(int index);
void add(Object o);
Iterator getIterator();
}
I am not asking for you to provide me with the solution, however I was wondering if anyone had any idea what I am supposed to use the getIterator() method for? I am implementing this once using composition, and a second time using inheritance. I am guessing that I have to use an Iterator when adding an item to the List - I will iterate through the list and use a Comparator to compare each item, and then perform the ordered insertion. What is actually supposed to happen in the getIterator() method? Why must there be this method in both OrderedList and LinkedList?
getIterator would typically be used to return an Iterator that the user can use to walk the list in order and see all of the elements. Usage of it might look like
The key is that the iterator needs to return the items in order.
Jeff
Jeff Storey
Software Developer
[url]http://jeffastorey.blogspot.com[/url]
As you have defined your own ADT's (LinkedList etc..), do you have Iterator/Enumeration defined also? Then when getting a such, you should pass an implementation of that (either Iterator/Enumeration) with regards to the underlying datastructure you have. So that the users of that are able to traverse the list.