implement first() and last() in TreeSet

This commit is contained in:
Joel Dice 2011-09-29 18:25:41 -06:00
parent 84bcbbcaa3
commit a8bb0d074b

View File

@ -41,6 +41,18 @@ public class TreeSet<T> extends AbstractSet<T> implements Collection<T> {
add(item);
}
}
public T first() {
if (isEmpty()) throw new NoSuchElementException();
return set.first().value().value;
}
public T last() {
if (isEmpty()) throw new NoSuchElementException();
return set.last().value().value;
}
public Iterator<T> iterator() {
return new MyIterator<T>(set.first());