reverse the element order in the array
时间: 2024-04-29 12:25:09 浏览: 85
实现对顺序表的逆置
Sure, you can reverse the element order in an array by using a loop to iterate through the array and swapping each element with its corresponding element at the opposite end of the array. Here's some sample code in Python:
```
arr = [1, 2, 3, 4, 5]
for i in range(len(arr)//2):
temp = arr[i]
arr[i] = arr[len(arr)-i-1]
arr[len(arr)-i-1] = temp
print(arr)
```
This will output: `[5, 4, 3, 2, 1]`
阅读全文