Reversing an Array
Implementation of 2 of the methods which can be used to reverse an array.
Reversing Techniques :
Reversing Using Auxiliary Array :
void reverseByCopy(int a[], int n) {
int i, j, b[n]; // New array to store in reverse order
// Storing elements in 'b' array in reverse order
for (i = n-1, j = 0; i >= 0; i--, j++) {
b[j] = a[i];
}
// Overwriting 'a' array
for(int i = 0; i < n; i++) {
a[i] = b[i];
}
}Reversing by Swapping Elements :
Last updated