c#冒泡排序

int[] a = { 1, 8, 3, 6, 9, 4 };

        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])

                {
                    int 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();
posted @ 2024-02-23 14:29  過朢  阅读(9)  评论(0)    收藏  举报