List Iterator Remove()

后端 未结 4 604
天涯浪人
天涯浪人 2020-12-08 06:19

I have a list iterator that goes through a list and removes all the even numbers. I can use the list iterator to print out the numbers fine but I cannot use the list\'s remo

4条回答
  •  误落风尘
    2020-12-08 06:32

    Since iterators depend on the length of the structure remaining the same, most iterators do not allow a list to be changed while the iterator is in use. If you want to go through and change the list, you're going to have to use a loop independent of the iterator.

提交回复
热议问题