- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickSort.cpp
More file actions
Latest commit
39 lines (35 loc) · 647 Bytes
/
Copy pathQuickSort.cpp
File metadata and controls
39 lines (35 loc) · 647 Bytes
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
#include<iostream>
#include<iterator>
usingnamespacestd;
intPartition(int *H,int low ,int high)
{
int pivotkey = H[low];
while(low<high)
{
while(low<high&& H[high]>=pivotkey) high--;
swap(H[low],H[high]);
while(low<high&& H[low]<=pivotkey) low++;
swap(H[low],H[high]);
}
return low;
}
voidQsort(int *H ,int low,int high)
{
if(low<high)
{
int index = Partition(H,low,high);
Qsort(H,low,index-1);
Qsort(H,index+1,high);
}
}
voidQuickSort(int *H,int length)
{
Qsort(H,0,length-1);
}
intmain()
{
int H[] = {49,38,65,97,76,13,27,49};
QuickSort(H,8);
copy(H,H+8,ostream_iterator<int ,char>(cout,""));
cout<<endl;
}