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

    天天向上
  • 相关阅读:
    BUUCTF-[强网杯 2019]随便注
    Oracle 存储过程
    java.lang.OutOfMemoryError: Java heap space
    Oracle 约束
    Docker 学习1 容器技术基础入门
    Kubernetes 学习1 Devops 核心要点和k8s架构概述
    mysql Sql语句
    Shell 编程详解
    git 学习
    Linux awk学习
  • 原文地址:https://www.cnblogs.com/hg07/p/12733191.html
Copyright © 2011-2022 走看看