一天一个小算法的学习之冒泡排序

冒泡排序,也不用多说了,很多大神都写得比我详细的多..我写在这里,只是因为自己想搞懂其中的逻辑..

直接上代码:

 public static void BubblingWithSort (int[] arr)
{
    for (int i = 0; i < arr.Length; i++) {
        for (int j = 0; j < arr.Length - 1 - i; j++) {
            int temp;
            if (arr [j] > arr [j + 1]) {
                temp = arr [j];
                arr [j] = arr [j + 1];
                arr [j + 1] = temp;
            }
        }
    }
}
原文地址:https://www.cnblogs.com/jbw752746541/p/8676531.html