c#冒泡算法

 int temp;
            int[] a = { 2, 5, 8, 9, 10, 11, 7, 6 };
            for (int i = 0; i < a.Length-1; i++) {  //总共的次数
                for (int j = 0; j <a.Length-i-1; j++) {   //每次要比较的次数
                    if (a[j] > a[j+1]) {  //如果后一项比第一项大 则把最大数放在前面
                        temp = a[j];
                        a[j] = a[j+1];
                        a[j+1] = temp;
                    
                    }
                   
                }
              
            }
            for (int i = 0; i < a.Length; i++)
            {
                Console.WriteLine(a[i]);
            }
            Console.ReadKey();
原文地址:https://www.cnblogs.com/mengluo/p/4789664.html