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;
    }

    天天向上
  • 相关阅读:
    Run
    axios+Qs请求数据转表单格式
    Vue开发电子书app
    vue2.5开发去哪儿了流程
    ES6重度学习 demo实例
    JS 数组, 对象的增查改删(多语法对比)
    格式化时间戳的n种方法
    Vue中你忽略的点
    vscode代码格式化
    分隔符
  • 原文地址:https://www.cnblogs.com/hg07/p/12733191.html
Copyright © 2011-2022 走看看