CMSC 132A Lecture 32: Another Quiz
CMSC132A Lecture 32: Another Quiz
As promised from last time, we are having the quiz on the implementation of the
comparable. It makes use of an Iterator.
Boolean isSorted(Comparable(listOf<x> X){
Iterator<T> iter = iterable.iterator();
if (!iter.hasNext()) {
return true;
}
T t = iter.next();
while (iter.hasNext()) {
T t2 = iter.next();
if (t.compareTo(t2) > 0) {
return false;
}
t = t2;
}
return true;
}
Not much was covered after this.