-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathquicksort.java
More file actions
39 lines (37 loc) · 1.13 KB
/
Copy pathquicksort.java
File metadata and controls
39 lines (37 loc) · 1.13 KB
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
public class QuickSortArray {
public static void qsortmed(int[] arr,int l,int r){
if(r-l>0){
int pivot = (l+r)/2,low = l,high = r;
while(low<pivot && high > pivot){
while(arr[low]<arr[pivot])
low++;
while(arr[high]>arr[pivot])
high--;
if(arr[high]<arr[low]){
int temp = arr[high];
arr[high] = arr[low];
arr[low] = temp;
}
}
if(arr[low]>arr[pivot]){
int temp = arr[pivot];
arr[pivot] = arr[low];
arr[low] = temp;
}
if(arr[high]<arr[pivot]){
int temp = arr[pivot];
arr[pivot] = arr[high];
arr[high] = temp;
}
qsortmed(arr,l,pivot);
qsortmed(arr,pivot+1,r);
}
}
public static void main(String[] args) {
int[] arr = {1,2,9,10,7,4,2,76,34};
qsortmed(arr,0,arr.length-1);
for(int i:arr){
System.out.println(i);
}
}
}