12345678910111213141516171819202122232425262728293031323334353637383940 |
- #include <iostream>
- void reverseAroundMiddle(int* arr, int size) {
- int mid = (size + 1) / 2;
- int* temp = new int[size];
- for (int i = 0; i < mid; ++i) {
- temp[i] = arr[mid + i];
- }
- for (int i = mid; i < size; ++i) {
- temp[i] = arr[i - mid];
- }
- for (int i = 0; i < size; ++i) {
- arr[i] = temp[i];
- }
- delete[] temp;
- }
- int main() {
- int arr[] = {1, 2, 3, 4, 5, 6};
- int size = sizeof(arr) / sizeof(arr[0]);
- reverseAroundMiddle(arr, size);
- std::cout << "{";
- for (int i = 0; i < size; ++i) {
- std::cout << arr[i];
- if (i < size - 1) {
- std::cout << ", ";
- }
- }
- std::cout << "}" << std::endl;
- return 0;
- }
|