- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickSort.java
More file actions
Latest commit
37 lines (34 loc) · 858 Bytes
/
Copy pathQuickSort.java
File metadata and controls
37 lines (34 loc) · 858 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
importjava.util.*;
publicclassQuickSort {
publicstaticvoidmain(String[] args) {
int[] arr = { 5, 1, 4, 3, 2, 8 };
sort(arr, 0, arr.length - 1);
System.out.println(Arrays.toString(arr));
}
staticvoidsort(int[] arr, intlow, inthigh) {
if (low >= high) {
return;
}
ints = low;
inte = high;
intmid = s + (e - s) / 2;
intp = arr[mid];
while (s <= e) {
while (arr[s] < p) {
s++;
}
while (arr[e] > p) {
e--;
}
if (s <= e) {
inttemp = arr[s];
arr[s] = arr[e];
arr[e] = temp;
s++;
e--;
}
}
sort(arr, low, e);
sort(arr, s, high);
}
}