S
Sebastian
I would expect that in a linked list, an element can be added or
removed in constant time, assuming that the iterator is already
in the right position.
However, the Javadoc for JDK 1.6 says the following:
a) the iterator method of a LinkedList (defined in
AbstractSequentialList) merely returns a list iterator
over the list.
b) the remove() and set(Object) methods in ListIterator are not defined
in terms of the cursor position; they are defined to operate on the
last element returned by a call to next() or previous().
I am not sure how to understand that. Does it mean that removal from a
linked list, even through the remove method of an iterator over the
list, is implemented in terms of either the remove(int index)or
the remove(Object o) method? Which in a LinkedList would need to
traverse the list, making removal a linear time operation.
Am I missing something? Is the documentation simply wrong?
-- Sebastian
removed in constant time, assuming that the iterator is already
in the right position.
However, the Javadoc for JDK 1.6 says the following:
a) the iterator method of a LinkedList (defined in
AbstractSequentialList) merely returns a list iterator
over the list.
b) the remove() and set(Object) methods in ListIterator are not defined
in terms of the cursor position; they are defined to operate on the
last element returned by a call to next() or previous().
I am not sure how to understand that. Does it mean that removal from a
linked list, even through the remove method of an iterator over the
list, is implemented in terms of either the remove(int index)or
the remove(Object o) method? Which in a LinkedList would need to
traverse the list, making removal a linear time operation.
Am I missing something? Is the documentation simply wrong?
-- Sebastian