QList<int> mylist;QList<int>::iterator cur = mylist.begin();QList<int>::iterator last = mylist.end();while ( cur != last){ *cur = *cur - 1; if (*cur <= 0) { cur = mylist.erase(cur); last = mylist.end(); } else ++cur;};
QMutableListIterator<int> i(list); while (i.hasNext()) { int val = i.next(); if (val < 0) { i.setValue(-val); } else if (val == 0) { i.remove(); } }
QMutableListIterator<int> i(list); while (i.hasNext()) { int val = i.next(); if (val != 0) i.setValue(--val); else i.remove(); }
QMutableListIterator<int> i(list); while (i.hasNext()) { int val = i.next(); if (--val == 0) i.remove(); }
QMutableListIterator<int> i(list); while (i.hasNext()) { int val = i.next(); if (val == 0) i.remove(); }
QMutableListIterator<int> i(list); while (i.hasNext()) { int val = i.next(); val-=1; if (val != 0) i.setValue(val); else i.remove(); }
#include <Qt>#include <QDebug>int main(int argc, char *argv[]){ QList<int> list; list << 2 << 3 << 4 << 5 << 6; while(list.count()) { qDebug() << list; QMutableListIterator<int> i(list); while (i.hasNext()) { int val = i.next(); val-=1; if (val != 0) i.setValue(val); else i.remove(); } } return 0;}
$ ./test12(2, 3, 4, 5, 6)(1, 2, 3, 4, 5)(1, 2, 3, 4)(1, 2, 3)(1, 2)(1)
for ( QMutableListIterator<int> it( list ); it.hasNext(); ) if ( --it.next() == 0 ) it.remove();