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

    代码

    using namespace std; 
    int shuzu[]={15,14,5,24,18,19,4,58,12};
    void quicksort(int shuzu[],int left,int right);
    int main()
    {
        int left=0,right=8;
        quicksort(shuzu,left,right);
        for(left=0;left<9;left++)
            cout<<shuzu[left]<<" ";
        return 0;
    }
    void quicksort(int shuzu[],int left,int right)
    {
        int f;
        int ltemp=left,rtemp=right;
        f=shuzu[(left+right)/2];
        while(ltemp<rtemp)
        {
            while(shuzu[ltemp]<f)
                ltemp++;
            while(shuzu[rtemp]>f)
                rtemp--;
            if(ltemp<rtemp)
            {
                int temp=shuzu[ltemp];
                shuzu[ltemp]=shuzu[rtemp];
                shuzu[rtemp]=temp;
            }
        }
            if(left<rtemp)
            {
                quicksort(shuzu,left,ltemp-1);
            }
            if(ltemp<right)
                quicksort(shuzu,rtemp+1,right);
            return;
    }
  • 相关阅读:
    leetcode-String to Integer (atoi)
    2014薪水
    Ubunt下的软件集
    ubuntu常用软件
    python模块安装
    ubuntu下玩三国杀
    递归函数
    匿名函数
    装饰器函数
    生成器
  • 原文地址:https://www.cnblogs.com/puffmoff/p/8495376.html
Copyright © 2011-2022 走看看