-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquickSort.java
38 lines (33 loc) · 1.05 KB
/
quickSort.java
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
public class quickSort {
public static void main(String [] args){
int [] a = {1,3,0,3,6,5,8,2};
Sort(a, 0, a.length -1);
for (int i = 0; i<a.length -1;i++) {
System.out.print(a[i]+",");
}
System.out.print("\n");
}
public static void Sort(int [] res, int start , int end){
if(start >= end){
return;
}
int mid = quickSort(res, start, end);
Sort(res, start, mid-1);
Sort(res, mid +1,end);
}
public static int quickSort(int [] res , int lift, int right){
int tmp = res[lift];
while(lift<right){
while(lift<right&&res[right]>=tmp){
--right;
}
res[lift] = res[right];
while(lift<right&&res[lift]<=tmp){
++lift;
}
res[right] = res[lift];
}
res[lift] = tmp;
return lift;
}
}