Implement TreeSet#descendingIterator

If need be, this functionality can be sped up by implementing a
descending iterator on the tree without copying it into an ArrayList.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin 2013-11-01 20:20:05 -05:00
parent 1ed90c38ab
commit c023bd8654

View File

@ -56,6 +56,12 @@ public class TreeSet<T> extends AbstractSet<T> implements Collection<T> {
return new MyIterator<T>(set.first());
}
public Iterator<T> descendingIterator() {
ArrayList<T> iterable = new ArrayList<T>(this);
Collections.reverse(iterable);
return iterable.iterator();
}
public String toString() {
return Collections.toString(this);
}