选择排序

时间:2020-04-18 11:37:00   收藏:0   阅读:49
技术图片
 1 void selectSort(int array[], int n) {
 2     int current;
 3     for (current = 0; current < n; ++current) {
 4         int i, min = array[current], minIndex = current; 
 5         for (i = current; i < n; ++i) {
 6             if (array[i] < min) {
 7                 min = array[i];
 8                 minIndex = i;
 9             }
10         }
11         swap(&array[current], &array[minIndex]);
12     }
13 }
选择排序

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!