#include <iostream>
using namespace std;
void reverse(int array[], int x, int y)
{
for (int i = 0; i < x; i += y)
{
int l = i;
int r = min(i + y - 1, x- 1);
while (l < r)
swap(array[l++], array[r--]);
}
}
int main()
{
int array[] = {11, 12, 13, 14, 15, 16, 17, 18};
int y = 13;
int x = sizeof(array) / sizeof(array[0]);
reverse(array, x, y);
for (int i = 0; i < x; i++)
cout << array[i] << " ";
return 0;
}
Comments
Leave a comment