#include <iostream>
#include <vector>
using namespace std;
int main(void)
{
// 双指针翻转数组
vector<int> arr = {1, 2, 3, 4, 5, 6};
int start = 0;
int end = arr.size() - 1;
while (start < end)
{
int temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}
for (auto i : arr)
{
cout << i << " ";
}
cout << endl;
cout << "------------------" << endl;
// 倒序交换翻转数组
vector<int> arr1 = {1, 2, 3, 4, 5, 6};
for (int i = 0; i < arr1.size() / 2; i++)
{
int temp = arr1[i];
arr1[i] = arr1[arr1.size() - 1 - i];
arr1[arr1.size() - i - 1] = temp;
}
for (auto i : arr1)
{
cout << i << " ";
}
}
public class App {
// 数组逆序存放
public static void main(String[] args) {
int[] arr = new int[5];
for (int i = 0; i < arr.length; i++) {
arr[i] = i;
}
//翻转方法
for (int i = 0; i < arr.length / 2; i++) {
int temp = arr[i];
arr[i] = arr[arr.length - i - 1];
arr[arr.length - i - 1] = temp;
}
for (int i : arr) {
System.out.println(i);
}
//--------------------------------------------------------------
System.out.println("------------------------------------------------------------");
int[] arr1 = new int[5];
for(int i = 0; i < arr1.length; i++){
arr1[i] = i;
}
int start = 0;
int end = arr1.length - 1;
while(start < end) {
int temp = arr1[start];
arr1[start] = arr1[end];
arr1[end] = temp;
start++;
end--;
}
for(int i : arr1) {
System.out.println(i);
}
}
}