0 1 2 3 4
| | | | |
|--1--|--2--|--3--|--4--|
| | | | |
1 2 3 4 5
Venerable source of coding errors. for (int i=0;i<4;++i) // not <=.
Or: for (int i=sz(); i;) work(--i); // Less typing, but risky if body changes.
Delete on the run: for (auto j=T.begin(), j2; j!=T.end();) { // erase by iterator.
j2 = j++;
if (!ok(j2)) T.erase(j2);
}
nedwaves.com 2017 [171108]