zoukankan      html  css  js  c++  java
  • 排序 快速排序

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

                }
            }
        }
    }

  • 相关阅读:
    利用 Avisynth 2.5.8 的 ColorKeyMask 功能实现视频抠像
    Codebook model 视频抠像 xp sp3 + vs2005 + OpenCV 2.3.1
    call、apply、bind
    网络模型
    搜索关键字变色突出显示
    面向过程与面向对象编程的区别和优缺点
    webpack打包体积优化---插件 webpack-bundle-analyzer
    百度搜索关键词特效
    DNS原理及其解析过程
    亿级高并发数据库调优与最佳实践法则
  • 原文地址:https://www.cnblogs.com/handboy/p/7153330.html
Copyright © 2011-2022 走看看