#include <stdio.h> #define N 300
void print_source(int [],int); void print(int **,int); void sort(int **,int); int main(int argc, char *argv[]) { int data[N],*pstr[N],**p,i,n; printf("please input n:"); scanf("%d",&n); for (i = 0; i < n; i++) { pstr[i] = &data[i]; } p = pstr; for (i = 0; i < n; i++) { scanf("%d",*p++); } p = pstr; printf("the source data is :\n"); print(p,n); printf("the sort result:\n"); p = pstr; sort(p,n); p = pstr; print(p,n); printf("array source data is :\n"); print_source(data,n); system("pause"); return 0; }
void print(int **p, int n) { int i; for (i = 0; i < n; i++) { printf("%d ",**p++); } printf("\n"); }
void sort(int **p, int n) { int i,j,k,*temp; for (i = 0; i < n - 1; i++) { k = i; for (j = i + 1; j < n; j++) { if (**(p + k) > **(p + j)) { k = j; } } if (k != i) { temp = *(p + i); *(p + i) = *(p + k); *(p + k) = temp; } } }
void print_source(int arr[],int n) { int i; for (i = 0; i < n; i++) { printf("%d ",arr[i]); } printf("\n"); }
|