#include <stdio.h>
void maopao_asc_sort(int[],int); void print_shuzu(int[],int); void maopao_desc_sort(int[],int); int main() { int a[11]={30,5,20,4,50,60,84,58,31,26,33}; printf("the soure data is :\n"); print_shuzu(a,11); maopao_asc_sort(a,11); printf("\nthe sorted numbers:\n"); print_shuzu(a,11); printf("\nthe desc sorted numbers:\n"); maopao_desc_sort(a,11); print_shuzu(a,11); system("pause"); return 1; }
void maopao_asc_sort(int a[],int n) { int i,j,t; for (i=0;i < n - 1;i++) { for (j=0;j<n - 1 - i;j++) { if(a[j] > a[j+1]) { t = a[j]; a[j] = a[j+1]; a[j+1] = t; } } } }
void maopao_desc_sort(int a[],int n) { int i,j,t; for (i=0;i < n - 1;i++) { for (j=0;j<n - 1 - i;j++) { if(a[j] < a[j+1]) { t = a[j]; a[j] = a[j+1]; a[j+1] = t; } } } }
void print_shuzu(int a[],int n) { int i; for (i=0;i<n;i++) { printf("%d ",a[i]); } }
|