Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
jbri
· 15y ago · 0 comments
Though you have to be careful with that, because the obvious code for removing from a collection in reverse:
for(i = list.size; i >= 0; i--) list.removeAt(i);
Is itself a schlemiel algorithm on any singly-linked list...
Comments
[–]
kzrdude
15y ago
You're removing i+1 elements here :)
[–]
Confusion
15y ago
That really depends on the implementation of the linked list. I don't think it would actually behave O(n^2) in most implementations.
[–]
willfarrell
15y ago
for(i = list.size; i--;) list.removeAt(i);