4 ms·
for (size_t i = 0; i < length; i++) { size_t j = (length - 1) - i; ... } EDIT: change i to j
by 10000truths 4y ago
for (size_t i = 0; i < length; i++) {
size_t j = (length - 1) - i;
...
}
EDIT: change i to j
- yuliyp 4y agoThat's quite broken (you'd want a different variable inside the body, vs clobbering the iteration counter, else this would process the last item in your list, then exit).
- unwind 4y agoUh no don't reassign the loop variable in the inner scope. Use: const j = (length - 1) - i; in that case. Much safer.
- rabbidruster 4y agoI hope you haven't done this anywhere. Makes my brain hurt, but I think this will only run through the loop one time looking at the last element of the array.
- Banana699 4y agoYou should save the old value of i somewhere and restore it back at the very end of the loop. Or simply define a new j like another comment says.