选择排序(select sort)

来源:互联网 发布:淘宝优惠券赚佣金算的 编辑:程序博客网 时间:2024/06/06 23:08

选择排序算法就是在待排序列中每次找到最大(最小)的关键字,并且放在已排好序的子序列的前面(后面),直到排序 结束。

时间复杂度为O(n^2)
稳定性:不稳定

C++实现代码:

template <typename T>void SelectSort(T arr[], int n){    for (int i = 0; i < n; i++)    {        int current_Minindex = i;        for (int j = i + 1; j < n; j++)        {            if (arr[j] < arr[current_Minindex])            {                current_Minindex = j;            }        }        swap(arr[i], arr[current_Minindex]);    }}
原创粉丝点击