-
Notifications
You must be signed in to change notification settings - Fork 4
/
quickSort.cc
56 lines (51 loc) · 1.08 KB
/
quickSort.cc
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
///
/// @file QuickSort.cc
/// @author yll(1711019653@qq.com)
/// @date 2019-01-23 17:06:49
///
#include <iostream>
using std::cout;
using std::endl;
class QuickSort
{
public:
static void quickSort(int array[],int low, int high)
{
while(low < high)
{
int part = partition(array, low, high);
quickSort(array, low, part-1);
//cout << "111" << endl;
quickSort(array, part+1, high);
//cout << "222" << endl;
return;
}
}
static int partition(int array[], int low, int high)
{
int parter = array[low];
while(low < high)
{
while((low < high) && (parter <= array[high]))
--high;
array[low] = array[high];
// cout << "high = " << high << " " ;
while((low < high && parter >= array[low]))
++low;
array[high] = array[low];
}
array[low] = parter;
cout << low << endl;
return low;
}
};
int main(void)
{
int *array = new int[15]{5,2,5,1,7,9,35,21,4,6,9,7,10,12,11};
//cout <<"111" << endl;
QuickSort::quickSort(array, 0, 14);
//cout << "222" << endl;
for(int i = 0; i < 15; ++i)
cout << array[i] << " " ;
cout << endl;
}