惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
人人都是产品经理
人人都是产品经理
The GitHub Blog
The GitHub Blog
月光博客
月光博客
T
Tailwind CSS Blog
小众软件
小众软件
Y
Y Combinator Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Proofpoint News Feed
B
Blog RSS Feed
博客园 - 司徒正美
A
About on SuperTechFans
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 聂微东
Microsoft Security Blog
Microsoft Security Blog
Recent Announcements
Recent Announcements
博客园 - Franky
U
Unit 42
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Azure Blog
Microsoft Azure Blog
T
The Blog of Author Tim Ferriss
GbyAI
GbyAI
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - 超薄

符号执行虚假控制流去混淆 ios 重启usb ubuntu 搜狗输入法安装 js 反hook js 源码乱码 js和html加上混淆 js 字体加密 jj混淆 webpack 暴力方式扣取 志远js调试相关 并行算法中的异常 事件模式实现通知 扩展属性应用 位运算应用口诀和实例(转自大笨狼) 数据结构实际应用----订单排序(堆排序求前N大) 数据结构Tire 树实际应用----过滤禁词 动态规划 字典 DictionaryBase 和 SortedList 模式匹配文本处理 位运算
快速排序算法
超薄 · 2012-02-11 · via 博客园 - 超薄

快速排序算法是最快的排序算法,当然它是针对大量通常无序的集合而言是正确的。

public void QSort()

{

    RecQSort(0, numElements - 1);

}

public void RecQSort(int first, int last)

{

    if ((last - first) <= 0)

        return;

    else

    {

        int part = this.Partition(first, last);

        RecQSort(first, part - 1);

        RecQSort(part + 1, last);

    }

}

public int Partition(int first, int last)

{

    int pivotVal = arr[first];

    int theFirst = first;

    bool okSide;

    first++;

    do

    {

        okSide = true;

        while (okSide)

            if (arr[first] > pivotVal)

                okSide = false;

            else

            {

                first++;

                okSide = (first <= last);

            }

        okSide = true;

        while (okSide)

            if (arr[last] <= pivotVal)

                okSide = false;

            else

            {

                last--;

                okSide = (first <= last);

            }

        if (first < last)

        {

            Swap(first, last);

            this.DisplayElements();

            first++;

            last--;

        }

    } while (first <= last);

    Swap(theFirst, last);

    this.DisplayElements();

    return last;

}

public void Swap(int item1, int item2)

{

    int temp = arr[item1];

    arr[item1] = arr[item2];

    arr[item2] = temp;

}

如果数组内的的数据是随机的,那么选择第一个

最流行的选择中间值得方法。

theFirst = arr[(int)arr.GetUpperBound(0) / 2]