快排

    xiaoxiao2021-03-25  123

    好难受啊 

    发烧了

    一个快排也写了那么久

    zz

    还没有加上随机排序的部分

    怎么这么慢啊

    我也很绝望啊

    熟能生巧?

    好在是xcode弄好了

    sublime太不靠谱了

    //

    //  main.cpp

    //  leecode

    //

    //  Created by 陆炫宇 on 17/3/8.

    //  Copyright © 2017 陆炫宇. All rights reserved.

    //

    /*quicksort.cpp

     

     */

    #include<iostream>

    #include<string>

    //#include<math>

    using namespace std;

    void exchange(int *a,int p,int q){

        int temp=a[p];

        a[p]=a[q];

        a[q]=temp;

    }

    //sorting

    void old_partition(int *a,int begin,int ed){

        cout<<"begin:ed"<<begin<<":"<<ed<<endl;

        int p=begin;

        int q=ed;

        if(p>=q)

            return;

        bool flag=true;

        while(p<q){

            

            for(int i=0;i<5;i++)

                cout<<a[i];

            cout<<endl;

            if(flag){

            if(a[p]>a[q]){

                exchange(a,p,q);

                flag=!flag;

                

                p++;

                

            }

            else{

                q--;

            }

            cout<<"p: q:"<<p<<":"<<q<<endl;

            }

            else{

                if(a[p]>a[q]){

                    exchange(a,p,q);

                    flag=!flag;

                    

                    q--;

                    

                }

                else{

                    p++;

                }

            }

            

        }

        old_partition(a,begin,p-1);

        old_partition(a,p+1,ed);

        

    }

    int main(){

        int a[]={3,4,5,1,2};

        

        old_partition(a,0,4);

        for(int i=0;i<5;i++)

            cout<<a[i];

        cout<<endl;

    }

    转载请注明原文地址: https://ju.6miu.com/read-7825.html

    最新回复(0)