forked from sPredictorX1708/Ultimate-Java-Resources
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickSort.java
More file actions
28 lines (28 loc) · 746 Bytes
/
QuickSort.java
File metadata and controls
28 lines (28 loc) · 746 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
public class QuickSort{
public static void swap (int a [], int i, int j){
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
public static void quickSort(int [] a, int l, int r){
if (l < r){
int p = r;
int i = l;
int j = r-1;
do {
while (a[i] <= a[p] && i <= j) i++;
while (a[j] >= a[p] && i <= j) j--;
if (i < j){
swap (a, i, j);
i++;
j--;
}
}
while (i < j);
swap (a, i, r);
print (a);
quickSort (a, l, i-1);
quickSort (a, i+1, r);
}
}
}