-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickSort.java
More file actions
37 lines (31 loc) · 744 Bytes
/
QuickSort.java
File metadata and controls
37 lines (31 loc) · 744 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
import java.util.Arrays;
public class QuickSort{
public static void main(String args[]){
int arr[] = {4,7,2,9,6,1};
QuickSort.quick(arr,0,arr.length-1);
System.out.println(Arrays.toString(arr));
}
public static void quick(int arr[],int low,int high){
if(low>=high){
return;
}
int s = low;
int e = high;
int mid = arr[s+(e-s)/2];
while(arr[s]<mid){
s++;
}
while(arr[e]>mid){
e--;
}
if(s<=e){
int temp = arr[s];
arr[s] = arr[e];
arr[e] = temp;
s++;
e--;
}
quick(arr, low, e);
quick(arr, s, high);
}
}