-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquicksort.java
More file actions
36 lines (30 loc) · 796 Bytes
/
Copy pathquicksort.java
File metadata and controls
36 lines (30 loc) · 796 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
import java.util.Arrays;
public class quicksort {
public static void main(String[] args) {
int[] arr = {-1,2,6,5,4,7,8,9,11,0};
sorting(arr,0,arr.length-1);
System.out.println(Arrays.toString(arr));
}
private static void sorting(int[] arr, int low, int hi) {
if(low >= hi)
return;
int s = low;
int e = hi;
int piv = s + (e - s)/2;
while(s <= e){
while(arr[s]<arr[piv])
s++;
while(arr[e]>arr[piv])
e--;
if(s<=e){
int temp=arr[s];
arr[s]=arr[e];
arr[e]=temp;
s++;
e--;
}
}
sorting(arr,low,e);
sorting(arr,s,hi);
}
}