• 排序 快速排序


    原文发布时间为: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);

                }
            }
        }
    }

  • 相关阅读:
    2017年7月10日 20:34:02 简易博客记录组
    Oracle审计表AUD$处理方法 (Z)
    Oracle中trace的几种(Z)
    查看oracle数据库是否归档和修改归档模式(转)
    oracle exp-000991
    基于公司级平台封装的SqlserverHelper
    pycharm运行测试程序提示no tests were found
    10-13 验证用户
    10-11 喜欢的数字
    10-1 Python 学习笔记
  • 原文地址:https://www.cnblogs.com/handboy/p/7153330.html
Copyright © 2020-2023  润新知