-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquicksort.java
More file actions
40 lines (32 loc) · 812 Bytes
/
quicksort.java
File metadata and controls
40 lines (32 loc) · 812 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
39
40
public class quicksort {
static void quicksort(int[] x, int start, int end){
if(start+1==end){
return;
}
int small = start;
int big = end;
int pivot = x[(start+end)/2];
while(small<big){
while (x[small]<pivot){
small++;
}
while (x[big]>pivot){
big--;
}
if(small<big) {
int trans = x[big];
x[big] = x[small];
x[small] = trans;
small++;
big --;
}
}
quicksort(x,start,small);
quicksort(x,big,end);
}
public static void main(String[] args) {
// write your code
int[] x = {2,1};
quicksort(x,0,1);
}
}