Тема: ContainerIterator
Показать сообщение отдельно
Старый 18.06.2008, 18:36   #17  
Hyper is offline
Hyper
Участник
Соотечественники
 
163 / 29 (1) +++
Регистрация: 09.10.2003
Цитата:
Сообщение от Gustav Посмотреть сообщение
The only situation in which you cannot avoid using the iterator is when you must remove elements from a List collection. The following code shows how this is accomplished.
X++:
List list = new List(Types::Integer);
ListIterator iterator;
;
list.addEnd(100);
list.addEnd(200);
list.addEnd(300);

iterator = new ListIterator(list);
while (iterator.more())
{
    if (iterator.value() == 200)
        iterator.delete();
    iterator.next();
}
print list.toString(); //{100, 300}
pause;
В коде логическая ошибка. Перед iterator.next() необходим else.
За это сообщение автора поблагодарили: Gustav (2).