forked from Dipak3007/Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickSort_Ashok.java
More file actions
35 lines (35 loc) · 966 Bytes
/
QuickSort_Ashok.java
File metadata and controls
35 lines (35 loc) · 966 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
public class QuickSort {
public int partition(int [] arr,int low,int high){
int pivot=arr[low];
int i=low,j=high;
while(i<j){
while(arr[i]<=pivot && i<high) i++;
while(arr[j]>pivot) j--;
if(i<j){
int temp=arr[j];
arr[j]=arr[i];
arr[i]=temp;
}
}
int temp=pivot;
arr[low]=arr[j];
arr[j]=temp;
return j;
}
public void quickSort(int []arr,int low,int high){
if(low<high){
int j=partition(arr, low, high);
quickSort(arr, low, j-1);
quickSort(arr, j+1,high);
}
}
public static void main(String[] args) {
int arr[]={23,54,34,16,78,11,70};
int low=0,high=arr.length-1;
SortQuick q1=new SortQuick();
q1.quickSort(arr,low,high);
for (int i : arr) {
System.out.print(i+" ");
}
}
}