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;
            }
        }
    }
}
原文地址:https://www.cnblogs.com/bingxing/p/6716789.html