//选择排序


//选择排序
#include "stdafx.h"
using namespace std;
#include<vector>
#include<string>

class Solution
{
public:

    static int* bubbleSort(int* array, int len)
    {
        
        for (int i = 0; i < len; i++)
        {
            int minIndex = i;
            for (int j = i; j < len; j++)
            {
                if (array[j] < array[minIndex]) //找到最小的数
                {
                    minIndex = j; //将最小数的索引保存
                }
            }
            int temp = array[minIndex];
            array[minIndex] = array[i]; //把最开始比较的数放到 未排序的数组中的最小的数的位置;
            array[i] = temp;     //把最头的位置的数换成上面找到的最小的数

        }
        return array;
    }

};


int main()
{
    int aa[]  = { 1, 5, 6, 7, 2, 3 };
    Solution sou;
    sou.bubbleSort(aa, 6);
    return 1;
}

天天向上
原文地址:https://www.cnblogs.com/hg07/p/12733191.html