简单排序之选择排序

 1 void select_sort()
 2 {
 3     int i,j,k;
 4     unsigned char array[10] = {4,1,3,9,6,2,8,5,0,7};
 5     unsigned char len = sizeof(array);
 6     unsigned char temp;
 7 
 8     for(i = 0; i< len-1; i++)
 9     {
10         k = i;
11         /*遍历所以有序序列,排序*/
12         for(j=i+1; j < len; j++)
13         {            
14             if(array[j] < array[k])
15             {      
16                k = j;
17             }            
18         }
19         temp = array[i];
20         array[i] = array[k];
21         array[k] = temp;
22     }
23     for(i=0;i<10;i++)
24     {
25         printf("%d\n",array[i]);
26     }
27 }

 

posted @ 2023-08-28 16:49  njit-sam  阅读(5)  评论(0编辑  收藏  举报