I'm doing a Java implementation for a Doubly-linked list.
I have some methods like this:
private DLNode<T> getNodeAtPosition(int position) throws DLListException {
verifySize(this.listSize(), position);
DLNode<T> result = this.first;
for (int counter = 0; counter < position; counter++) { // <=======
result = result.next;
}
return result;
}
It can be done either with for/while loops or with iterators. Which one optimizes those methods? That's a important thing if you're trying to do a very used ADT.
I'm not meaning for-each loops, I mean loops where you have to stop before the end as this one, or generally any loop that has more than one termination condition.