
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LinkedList<String> linkList = new LinkedList<String>();//can't have a size...! | |
linkList.add("a"); | |
linkList.addFirst("b"); | |
linkList.addLast("c"); | |
System.out.println(linkList); | |
Iterator<String> descendingIterator = linkList.descendingIterator(); | |
while(descendingIterator.hasNext()){ | |
System.out.println(descendingIterator.next()); | |
} | |
calls up
public Iterator<E> descendingIterator() {
return new DescendingIterator();
}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Adapter to provide descending iterators via ListItr.previous */ | |
private class DescendingIterator implements Iterator { | |
final ListItr itr = new ListItr(size()); | |
public boolean hasNext() { | |
return itr.hasPrevious(); | |
} | |
public E next() { | |
return itr.previous(); | |
} | |
public void remove() { | |
itr.remove(); | |
} | |
} |
No comments:
Post a Comment