Thursday, October 18, 2007

When conditionally deleting from a list, iterate backward

My ex colleague once told me, if you need to delete some element of a list or array based on some condition, iterate though the list backward. That way, the index will remain the same while traversing the list. Never been in that situation, I thought.

I was faced with this problem recently and thinking about how to solve it, it seems not so straight forward. Then I remembered that advice. Problem solved, yay.

0 comments: