A
Andreas Leitgeb
In some app of mine I've got a LinkedList of items. Now,
I want to check the last couple of items for some condition.
In practice I expect the list to be about 30 elements
long, and only the last three elements to be actually
visited. Oh and the context is somewhat time-critical.
Now, I think that an Iterator (actually ListIterator) would be
appropriate for my task, but the only way to get one seems to be
through method listIterator(int index). I can't help, but passing
in the lists size for the index feels like it would search forward
completely through the list to obtain an iterator that starts
from end.
Is there some better way to just scan the "last few elements"
from a LinkedList, or can someone assure me that calling
listIterator with an index at end will be efficient, or
is it best to redesign my app to build up the list in reverse
order in the first place, so I can use a "normal" iterator?
Afaik, the LinkedList is doubly-linked, so iterating from the
end should be a breeze, but indexing rather costly...
What's java's idiom for C++/stl's list::rbegin() ?
I want to check the last couple of items for some condition.
In practice I expect the list to be about 30 elements
long, and only the last three elements to be actually
visited. Oh and the context is somewhat time-critical.
Now, I think that an Iterator (actually ListIterator) would be
appropriate for my task, but the only way to get one seems to be
through method listIterator(int index). I can't help, but passing
in the lists size for the index feels like it would search forward
completely through the list to obtain an iterator that starts
from end.
Is there some better way to just scan the "last few elements"
from a LinkedList, or can someone assure me that calling
listIterator with an index at end will be efficient, or
is it best to redesign my app to build up the list in reverse
order in the first place, so I can use a "normal" iterator?
Afaik, the LinkedList is doubly-linked, so iterating from the
end should be a breeze, but indexing rather costly...
What's java's idiom for C++/stl's list::rbegin() ?