• 标准的冒泡排序


    static void Main(string[] args)
            {
                //冒泡法
                int[] myArray = new int[10] { 0,2,1, 8, 3, 5, 6, 7, 4, 9 };
                int temp = 0;
                for (int i = 1; i < myArray.Length; i++)
                {
                    for (int j = 0; j < myArray.Length - i; j++)
                    {
                        // 如果 myArray[i] > myArray[i+1] ,则 myArray[i] 上浮一位
                        if (myArray[j] > myArray[j + 1])
                        {
                            temp = myArray[j];
                            myArray[j] = myArray[j + 1];
                            myArray[j + 1] = temp;
                        }
                    }
                }

                foreach (int x in myArray)
                {
                    Console.WriteLine(x);
                }

                Console.ReadKey();
            }

  • 相关阅读:
    声音走样
    Terrain
    输出循环小数
    解决代码中多余的空行
    与二进制有关的几道面试题
    反转一个整数
    DirectX常见编译错误及解决办法
    STLset
    Visual Studio Autoexpand Information for DirectX 9
    素数环谈代码优化
  • 原文地址:https://www.cnblogs.com/meroselove/p/2196304.html
Copyright © 2020-2023  润新知