zoukankan      html  css  js  c++  java
  • //选择排序


    //选择排序
    #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;
    }

    天天向上
  • 相关阅读:
    android 入门-Activity及 字体
    android 入门-安装环境
    PS 零基础训练1
    txt操作
    C#重绘TabControl
    ini操作
    C#编写ActiveX控件
    远程目录和文件判断
    c#一些操作
    c#消息窗体
  • 原文地址:https://www.cnblogs.com/hg07/p/12733191.html
Copyright © 2011-2022 走看看