zoukankan      html  css  js  c++  java
  • I两种冒泡算法

    两种冒泡算法:

    第一个循环,I 定位当前坐标,第二个循环 把 I 之后的每个数都与 I 比较(比 I 小的都去坐标I),第二个循环之后 坐标 I 为数组里最小的数值。

    效率比较高的冒泡算法:

    static void Sort(int[] arrSort)
    {
        int temp;
        for (int i = 0; i < arrSort.Length - 1; i++)
        {
            for (int j = i + 1; j < arrSort.Length; j++)
            {
                if (arrSort[i] > arrSort[j])
                {
                    temp = arrSort[i];
                    arrSort[i] = arrSort[j];
                    arrSort[j] = temp;
                }
            }
        }
    
    }

    第二种方法:(比较次数多)

    static void lowSort(int[] arrSort)
    {
        int temp;
        for (int i = 0; i < arrSort.Length - 1; i++)
        {
            for (int j = 0; j < arrSort.Length - i - 1; j++)
            {
                if (arrSort[j] > arrSort[j + 1])
                {
                    temp = arrSort[j];
                    arrSort[j] = arrSort[j + 1];
                    arrSort[j + 1] = temp;
                }
            }
        }
    }
  • 相关阅读:
    paxos算法
    List
    es资料汇总
    尚硅谷Kafka
    lostach安装配置
    zookeeper安装
    zookeeper配置详解
    C# 微信企业付款给个人之相关配置
    JS--正则表达式验证
    uniapp小程序--自定义分享标题
  • 原文地址:https://www.cnblogs.com/bingxing/p/6716789.html
Copyright © 2011-2022 走看看