实现数组倒序的方法
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> int main() { int i; void reverse(int x[], int n); int a[4] = { 0, 1, 2, 3 }; printf("原始数据排序:"); for (i = 0; i < 4; i++) { printf("%d", a[i]); } printf("\n"); reverse(a, 4);//只需要传入数组名,为首地址 printf("倒序后:"); for (i = 0; i < 4; i++) { printf("%d", a[i]); } while (1); return 0; } //int f(int arr[],int n)相当于 int f(int *arr,int n);按指针来翻译,传入的是数组的首地址 /*void reverse(int x[], int n) 0 { int temp, i, j, m; m = (n - 1) / 2; for (i = 0; i <= m; i++) { j = n-1-i; temp = x[i]; x[i] = x[j]; x[j] = temp; } }*/ void reverse(int *x, int n)//1 { int temp, i, j, m; m = (n - 1) / 2; for (i = 0; i <= m; i++) { j = n - 1 - i; temp = x[i]; x[i] = x[j]; x[j] = temp; } }
#学习路径#