Reversing an integer array
Posted: Sat Jan 03, 2004 8:51 pm
I've been trying to reverse an array for the last little while and I can't seem to get it right. Has anybody done this before?
The Place to Start for Operating System Developers
https://f.osdev.org/
Code: Select all
#include <algorithm>
int myarray[10];
reverse(myarray, myarray+10);
Code: Select all
for (i = 0; i < length / 2; i++)
swap(a + i, a + length - 1 - i);
Code: Select all
for (i = 0; i < length; i++)
b[i] = a[i + length - 1];
Code: Select all
for (i = 0; i < (length / 2); i++) {
tmp = a[i];
a[i] = a[length - (i+1)];
a[length - (i+1)] = tmp;
}