abc_begin

导航

排序_选择排序

 

 1 void selectSort(LineList R[], int n)  
 2 {  
 3     int i, j, index;  
 4     for (i = 1; i < n; i++)   
 5     {  
 6         index = i;  
 7         for (j = i + 1; j <= n; j++)  
 8         {  
 9             if (R[j].key < R[index].key)  
10             {  
11                 index = j;  
12             }  
13         }  
14   
15         if (index != i)  
16         {  
17             R[0].key = R[i].key;  
18             R[i].key = R[index].key;  
19             R[index].key = R[0].key;  
20         }  
21     }  
22 }  

 

posted on 2017-10-10 10:28  LastBattle  阅读(143)  评论(0编辑  收藏  举报