#include <iostream>
using namespace std;
void DoVer(int arr[], int begin, int end) {
int i, j, temp;
for (i = begin, j = end; i < j; ++i, --j) {
swap(arr[i], arr[j]);
}
}
void Reverse(int arr[], int n, int p) {
if (p <= 0 || p >= n) {
return;
} else {
DoVer(arr, 0, p - 1);
DoVer(arr, p, n - 1);
DoVer(arr, 0, n - 1);
}
}
void Show(int arr[], int n) {
for (int i = 0; i < n; ++i) {
cout << arr[i] << " ";
}
}
int main() {
int arr[10] = {12, 3, 45, 65, 54, 34, 78, 9, 10, 23};
Reverse(arr, 10, 3);
Show(arr, 10);
return 0;
}
整体移动
最新推荐文章于 2023-11-06 20:40:04 发布