码迷,mamicode.com
首页 > 编程语言 > 详细

选择排序的总结

时间:2016-09-11 00:10:35      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:

数据结构排序算法之——选择排序(Select Sort)

 

选择排序想关链接:

维基百科:https://zh.wikipedia.org/zh/%E9%80%89%E6%8B%A9%E6%8E%92%E5%BA%8F

百度百科:http://baike.baidu.com/view/547263.htm

 

选择排序的基本思想:

就是每次在无序的数组选择一个一个最小的(或者最大的)数,放在已经有序的后面

 

代码

void Select_Sort(int array[], int arrayLen)

{

 

    for (int i = 0; i < arrayLen; ++i)

    {

        int tempIndex = i;

        for (int j = i + 1; j < arrayLen; ++j)

        {

            // 由小到大

 

            if (array[j] < array[tempIndex])

            {

                tempIndex = j;

            }

        }

 

        if (i != tempIndex)

        {

            Swap_IntVal(array + i, array + tempIndex);

        }

    }

}

 

详细的代码:代码地址应该会选择放在github,但是最近我对github的操作还不是很熟悉

选择排序的总结

标签:

原文地址:http://www.cnblogs.com/bkcarlos/p/5860646.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!