思路:定义一个左指针和一个右指针,然后判断大小,然后交换
#include <iostream> using namespace std; int main() { int arr[] = {1,2,3,4,5,6,7} ; int left = 0; int right = sizeof(arr) / sizeof(arr[0]) - 1; while (left < right){ int temp = arr[left]; arr[left] = arr[right]; arr[right] = temp; left++; right--; } for (int i = 0; i < 7; ++i) { cout<< arr[i] <<endl; } return 0; }