-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.cpp
More file actions
47 lines (42 loc) · 755 Bytes
/
Test.cpp
File metadata and controls
47 lines (42 loc) · 755 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
40
41
42
43
44
45
46
47
/*
//
// Created by YangYang on 2022/9/1.
//
*/
/*
快速排序
*/
#include <iostream>
#include <algorithm>
using namespace std;
//快速排序
void quickSort(int *a, int left, int right) {
if (left >= right) {
return;
}
int i = left;
int j = right;
int key = a[left];
while (i < j) {
while (i < j && a[j] >= key) {
j--;
}
a[i] = a[j];
while (i < j && a[i] <= key) {
i++;
}
a[j] = a[i];
}
a[i] = key;
quickSort(a, left, i - 1);
quickSort(a, i + 1, right);
}
int main()
{
int a[10] = {1, 3, 5, 7, 9, 2, 4, 6, 8, 10};
quickSort(a, 0, 9);
for (int i = 0; i < 10; i++) {
cout << a[i] << " ";
}
return 0;
}