1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#include <iostream>;
using namespace std;
void Quicksort(int info[],int left,int right){
int pivot = left + (right - left)/2;//it is the middle (will change sometimes but will end up in the middle
int temp;
while(left<=right){
while(info[left] < pivot){
left++;
}
while(info[right] > pivot){
right--;
}
//swap feature
if(left<=right){
temp = info[left];
info[left]=info[right];
info[right] = temp;
left ++;
right --;
}
}
}
int main(){
int Test[20]={1,2,5,6,7,8,9,21,42,3,57,22,36,4,9,10,11,12,20,35};
Quicksort(Test,0,19);
for(int i=0;i<20;i++){
cout << Test[i]<< "\n";
}
system("PAUSE");
return 0;
}
|