<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          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<<"請輸入要排序的元素個數(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.ex-cimer.com/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)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();