![]() |
#2
feng1008wd2013-10-29 17:53
回复 楼主 feng1008wd
|

#include<iostream>
using namespace std;
int Part(int* a,int low,int high){
int temp=a[low];
int j=high,i=low;
while(low<high){
while(a[high]>=temp&&high>low){
high--;
}
a[low]=a[high];
while(a[low]<=temp&&high>low){
low++;
}
a[high]=a[low];
}
a[low]=temp;
return low;
}
void qsort(int* a,int low,int high){
int pivotpos;
while(low<=high){
pivotpos=Part(a,low,high);
qsort(a,low,pivotpos-1);
qsort(a,pivotpos,high);
}
}
int main(){
int sort[10]={23,29,18,89,5,0,35,23,67,78};
qsort(sort,0,9);
for(int i=0;i<10;i++){
cout<<sort[i];
}
system("pause");
return 0;
}
using namespace std;
int Part(int* a,int low,int high){
int temp=a[low];
int j=high,i=low;
while(low<high){
while(a[high]>=temp&&high>low){
high--;
}
a[low]=a[high];
while(a[low]<=temp&&high>low){
low++;
}
a[high]=a[low];
}
a[low]=temp;
return low;
}
void qsort(int* a,int low,int high){
int pivotpos;
while(low<=high){
pivotpos=Part(a,low,high);
qsort(a,low,pivotpos-1);
qsort(a,pivotpos,high);
}
}
int main(){
int sort[10]={23,29,18,89,5,0,35,23,67,78};
qsort(sort,0,9);
for(int i=0;i<10;i++){
cout<<sort[i];
}
system("pause");
return 0;
}