Last Updated: February 25, 2016
·
271
· redaced

Quick Sort

include<iostream>

include<cmath>

include<cstring>

include<windows.h>

using namespace std;
int a[1000];
int partition(int* a, int p, int r){
int pivot = a[r];
while(p<r){
while(a[p]<pivot)
p++;
while(a[r]>pivot)
r--;
if(a[p] == a[r])
p++;
else{
int tmp = a[p];
a[p]= a[r];
a[r]= tmp;
}
}
return r;
}
void quicksort(int* input, int p, int r){
if(p<r){
int j = partition(input, p ,r);
quicksort(input, p, j-1);
quicksort(input, j+1, r);
}
}
int main(){
int num,i;
cin>>num;
cout<<endl;
for(i=0;i<num;i++){
cin>>a[i];
}
quicksort(a,0,num-1);
for(i=0;i<num;i++)
cout<<a[i]<<" ";
cout<<endl<<endl<<endl<<endl;
}