zoukankan      html  css  js  c++  java
  • Quick Sort

      

     1 #include <iostream>
     2 using namespace std;
     3 int partition(int *Ary,int low ,int high){
     4     int temp;
     5     int pivotkey=Ary[low];
     6     while(low<high){
     7         while(low<high && Ary[high]>=pivotkey){
     8             high--;
     9         }
    10         temp=Ary[low];
    11         Ary[low]=Ary[high];
    12         Ary[high]=temp;
    13         while(low<high && Ary[low]<=pivotkey){
    14             low++;
    15         }
    16         temp=Ary[low];
    17         Ary[low]=Ary[high];
    18         Ary[high]=temp;
    19     }
    20     return low;
    21 }
    22 void Qsort(int *Ary,int low,int high){
    23     if(low<high){
    24         int key=partition(Ary,low,high);
    25         
    26         Qsort(Ary,low,key-1);
    27         Qsort(Ary,key+1,high);
    28     }
    29     
    30 }
    31 int main(int argc, char *argv[]) {
    32     
    33     cout<<"Plz enter 10 numbers which then will be sorted"<<endl;
    34     int Ary[10] ;
    35     for (int i=0;i<10;i++){
    36         cin>>Ary[i];
    37     }
    38     int length=(sizeof(Ary)/sizeof(int));
    39     Qsort(Ary,0,length-1);
    40     for(int j=0;j<10;j++){
    41         cout<<Ary[j]<<" ";
    42     }
    43     return 0;
    44     
    45 }
  • 相关阅读:
    cf B. Vasily the Bear and Fly
    hdu 3339 In Action
    hdu 六度分离
    cf A. Vasily the Bear and Triangle
    cf C. Secrets
    2.19学习笔记|2.20学习笔记
    VAE代码学习
    2.9日学习记录
    deconvolution反卷积(待学习)
    gamma分布学习
  • 原文地址:https://www.cnblogs.com/wuruofeng/p/9786500.html
Copyright © 2011-2022 走看看