-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickSort.java
More file actions
38 lines (32 loc) · 817 Bytes
/
Copy pathquickSort.java
File metadata and controls
38 lines (32 loc) · 817 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
package sort;
import Util.Util;
public class quickSort {
//得调用递归,之前不用递归出不来...
public int[] sort(int[] a,int low,int high){
if(low<high)
{
int index = partition(a,low,high);
sort(a,low,index-1);
sort(a,index+1,high);
}
return a;
}
public int partition(int[] a,int low,int high)
{
int pivot = a[low];
while(low<high)
{
while(low<high && pivot <= a[high])
{
high--;
}
a[low] = a[high];//由于有个副本pivot,所以直接覆盖了
while(low<high && pivot >= a[low]){
low++;
}
a[high] = a[low];
}
a[low] = pivot;
return low;
}
}