快速排序

#include <iostream>

using namespace std;
void QuickSort(int *array,int left,int right)
{
    if(left>=right)
    {
        return;
    }
    else
    {
        int Base=array[left];
        int low=left;
        int high=right;

        while(low<high)
        {
            while(array[high]>=Base&&low<high)
            {
                high--;
            }
            array[low]=array[high];

            while(array[low]<=Base&&low<high)
            {
                low++;
            }
            array[high]=array[low];

        }
        array[low]=Base;
        QuickSort(array,left,low-1);
        QuickSort(array,low+1,right);
    }

}

int main()
{
    int array[]= {2,5,8,9,1,5,6,2};
    QuickSort(array,0,7);
    for(int i=0; i<=7; i++)
        cout<<array[i];
    return 0;
}
原文地址:https://www.cnblogs.com/handsometaoa/p/15253998.html