一本精品热在线视频,久久免费视频分类,精品婷婷乱码久久久久久蜜桃,在线可以免费观看的Av

<mark id="vd61v"><dl id="vd61v"></dl></mark>
    <sub id="vd61v"><ol id="vd61v"></ol></sub>

  • <sub id="vd61v"><ol id="vd61v"></ol></sub>

    新聞中心

    EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 用VC++類實(shí)現(xiàn)快速排序(并輸出過程)

    用VC++類實(shí)現(xiàn)快速排序(并輸出過程)

    作者: 時(shí)間:2016-12-01 來源:網(wǎng)絡(luò) 收藏


    &&&&&&&&&&&&&&&&&&&&&&&&&&&&主函數(shù)&&&&&&&&&&&&&&&&&&&&&&
    #include
    #include
    #include
    #include "WangQi.h"
    using namespace std;
    #define MAX 100
    void main(){
    SeqList L;
    int num;
    cout<<"請輸入要排序的元素個(gè)數(shù):"<cin>>num;
    cout<<"請輸入要排序的元素:"<for(int i=1;i<=num;i++)
    cin>>L.r[i];
    L.length=num;
    //輸出排序前的順序表
    L.output(&L,1,L.length,-1);
    L.quicksort(&L,1,L.length);
    L.output(&L,1,L.length,-2);
    }
    &&&&&&&&&&&&&&&&&&&含有類定義的頭文件&&&&&&&&&&&&&&&&&&&&&&&&&
    #include
    using namespacestd;
    #define MAX 100
    class SeqList{
    public:
    int r[MAX+1];
    int length;

    本文引用地址:http://www.ekcard.cn/article/201612/324137.htm

    void output(SeqList *L,int low, int high,int pivotloc){
    int i;

    if(pivotloc==-1||pivotloc==-2){
    if(pivotloc==-1)
    cout<<"初始狀態(tài):{"<< ;
    else cout<<"排序結(jié)果:{"<< ;
    for(i=low;i<=high;i++)
    cout<r[i]<< ;
    cout<<"}";
    }else {
    cout<<"劃分結(jié)果:{"<< ;
    for(i=low;i cout<r[i]<< ;
    cout<<"}"<r[pivotloc]<<"{";
    for(i=pivotloc+1;i<=high;i++)
    cout<r[i]<< ;
    cout<<"}";
    }
    cout<<<}


    int partition(SeqList *L,int low,int high){
    int pivotkey;
    int temp1=low,temp2=high;
    L->r[0]=L->r[low];
    pivotkey=L->r[low];
    while (low while (lowr[high]>=pivotkey)
    --high;
    L->r[low]=L->r[high];
    while(lowr[low]<=pivotkey)
    ++low;
    L->r[high]=L->r[low];
    }
    L->r[low]=L->r[0];
    output(L,temp1,temp2,low);
    return low;
    }


    void quicksort(SeqList *L,int low,int high){
    int pivotloc;
    if(low pivotloc=partition(L,low,high);
    if(low quicksort(L,low,pivotloc-1);
    if(high>pivotloc+1)
    quicksort(L,pivotloc+1,high);
    }
    };



    關(guān)鍵詞: VC++快速排序輸出過

    評論


    相關(guān)推薦

    技術(shù)專區(qū)

    關(guān)閉