-
Notifications
You must be signed in to change notification settings - Fork 0
/
6-4.js
34 lines (25 loc) · 763 Bytes
/
6-4.js
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
const solution = () => {
const array = [7, 5, 9, 0, 3, 1, 6, 2, 4, 8];
const quickSort = (array, start, end) => {
if (start >= end) return;
const pivot = start;
let left = start + 1;
let right = end;
while (left <= right) {
while (left <= end && array[left] <= array[pivot]) {
left += 1;
}
while (right > start && array[right] >= array[pivot]) {
right -= 1;
}
if (left > right)
[array[right], array[pivot]] = [array[pivot], array[right]];
else [array[right], array[left]] = [array[left], array[right]];
}
quickSort(array, start, right - 1);
quickSort(array, right + 1, end);
};
quickSort(array, 0, array.length - 1);
console.log(array);
};
solution();