-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha_QuickSort.cpp
More file actions
56 lines (53 loc) · 1.18 KB
/
a_QuickSort.cpp
File metadata and controls
56 lines (53 loc) · 1.18 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<iostream>
#include<conio.h>
using namespace std;
int quick(int a[],int l,int u){
int loc,left,right,temp;
left=l;
loc=l;
right=u;
while(left<right){
while(a[loc]<=a[right] && left<right){
right--;
}
if(left==right){
break;
}
else{
temp=a[loc];
a[loc]=a[right];
a[right]=temp;
loc=right;
}
while(a[loc]>a[left] && left<right) {
left++;
}
if(left==right)
break;
else{
temp=a[left];
a[left]=a[loc];
a[loc]=temp;
loc=left;
}
}
return loc;
}
void Quick_sort(int A[],int l,int u){
int loc;
loc=quick(A,l,u);
if(l+1<loc){
Quick_sort(A,l,loc-1); // using recursion
}
if(u-1>loc){
Quick_sort(A,loc+1,u);
}
}
int main(){
int Q[14]={50,23,81,11,90,100,66,72,14,31,44,75,29,13};
Quick_sort(Q,0,13);
for(int i=0;i<14;i++){
cout<<Q[i]<<" ";
}
return 0;
}