-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquickSort.cpp
51 lines (36 loc) · 891 Bytes
/
quickSort.cpp
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
#include <array>
#include <cstdio>
#include <cstdlib>
extern "C" {
void asmQuickSort(int list[], int left, int right);
}
std::array<int, 5> arr1 = {7, 3, 8, 9, 6};
std::array<int, 5> arr2;
static int division(int list[], int left, int right) {
int base = list[left];
while (left < right) {
while (left < right && list[right] >= base) {
right--;
}
list[left] = list[right];
while (left < right && list[left] <= base) {
left++;
}
list[right] = list[left];
}
list[left] = base;
return left;
}
static void quickSort(int list[], int left, int right) {
if (left < right) {
int base = division(list, left, right);
quickSort(list, left, base - 1);
quickSort(list, base + 1, right);
}
}
int main() {
arr2 = arr1;
quickSort(arr1.data(), 0, arr1.size() - 1);
asmQuickSort(arr2.data(), 0, arr2.size() - 1);
return 0;
}