标签:
4-4 SelectSort.c:
1 #include <stdio.h> 2 #include "4-1 CreateData.c" 3 #define ARRAYLEN 10 4 void SelectSort(int a[],int n) 5 { 6 int i,j,t,k; 7 for(i=0;i<n-1;i++) 8 { 9 k=i; 10 for(j=i+1;j<n;j++) 11 if(a[k]>a[j]) k=j; 12 t=a[i]; 13 a[i]=a[k]; 14 a[k]=t; 15 } 16 } 17 int main() 18 { 19 int i,a[ARRAYLEN]; 20 for(i=0;i<ARRAYLEN;i++) 21 a[i]=0; 22 if(!CreateData(a,ARRAYLEN,1,100)) 23 { 24 printf("生成随机数不成功!\n"); 25 getch(); 26 return 1; 27 } 28 printf("原数据:"); 29 for(i=0;i<ARRAYLEN;i++) 30 printf("%d ",a[i]); 31 printf("\n"); 32 SelectSort(a,ARRAYLEN); 33 printf("排序后:"); 34 for(i=0;i<ARRAYLEN;i++) 35 printf("%d ",a[i]); 36 printf("\n"); 37 getch(); 38 return 0; 39 }
标签:
原文地址:http://www.cnblogs.com/wozixiaoyao/p/5683151.html