• 排序 快速排序


    原文发布时间为:2009-03-06 —— 来源于本人的百度文章 [由搬家工具导入]

    using System;//快速排序

    namespace sorts
    {
        class Class7
        {
            public static void Main()
            {
                int[] a = new int[] { 4, 5, 8, 4, 6, 8, 5, 7 };
                QuickSort(a, 0, a.Length - 1);
                for (int i = 0; i < a.Length; i++)
                    Console.Write("{0} ", a[i]);
                Console.ReadLine();
            }

            public static void QuickSort(int[] a, int s, int t)
            {
                int i, j, tmp;
                i = s;
                j = t;
                if (s < t)
                {
                    tmp = a[s];
                    while (i != j)
                    {
                        while (j > i && a[j] > tmp)
                            j--;
                        if (i < j)
                        {
                            a[i] = a[j];
                            i++;
                        }
                        while (i < j && a[i] < tmp)
                            i++;
                        if (i < j)
                        {
                            a[j] = a[i];
                            j--;
                        }
                    }

                    a[i] = tmp;
                    QuickSort(a, s, i - 1);
                    QuickSort(a, i + 1, t);

                }
            }
        }
    }

  • 相关阅读:
    288.软件开发过程与软件测试
    287.软件测试概述
    离散数学课程重点
    博客园美化
    渗透测试-Getshell总结
    C++迭代器
    每日一题2
    计算机网络面试总结(传输层)
    每日一题-1
    网络安全必备技能
  • 原文地址:https://www.cnblogs.com/handboy/p/7153330.html
Copyright © 2020-2023  润新知