简单选择排序

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 
 4 void SelectSort(int *a, int l)
 5 {
 6     int min;
 7     for (int i = 0; i < l; ++i)
 8     {
 9         for(int j = i + 1; j<l; j++)
10         {
11             if(a[j] < a[i])
12             {
13                 min = a[j];
14                 a[j] = a[i];
15                 a[i] = min;
16             }
17         }
18     }
19 }
20 
21 int main(int argc, char const *argv[])
22 {
23     int a[] = {27,13,76,97,65,38,49};
24     int l = sizeof(a)/sizeof(a[1]);
25     SelectSort(a,l);
26 
27     for (int i = 0; i < l; ++i)
28     {
29         printf("%d ",a[i]);
30     }
31     printf("\n");
32     return 0;
33 }

 

posted @ 2019-03-31 21:59  Ghost4C  阅读(130)  评论(0编辑  收藏  举报