-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickSortThreeWay.java
More file actions
36 lines (32 loc) · 881 Bytes
/
quickSortThreeWay.java
File metadata and controls
36 lines (32 loc) · 881 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
public class quickSortThreeWay {
private static void quickSort(int arr[], int l, int h){
if(l < h){
int pivot = partition(arr,l,h);
quickSort(arr,l,pivot-1);
quickSort(arr,pivot+1,h);
}
}
private static int partition(int arr[], int l,int h){
int i = l;
int j = h;
while(i < j){
if(arr[i] > arr[j]){
swap(arr,i,j);
}
i++;
}
return j;
}
private static void swap(int arr[], int l,int h){
int tmp = arr[l];
arr[l] = arr[h];
arr[h] = tmp;
}
public static void main(String args[]) {
int arr[] = {4, 9, 4, 4, 1, 9, 4, 4, 9, 4, 4, 1, 4};
quickSort(arr,0,arr.length-1);
for(int i = 0; i < arr.length;i++){
System.out.print(arr[i]+" ");
}
}
}