forked from mrizky-kur/Redux-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuickSorting.java
41 lines (39 loc) · 1.07 KB
/
QuickSorting.java
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
40
41
public class QuickSorting {
static void Swap(int []array,int i,int j){
int temp=array[i];
array[i]=array[j];
array[j]=temp;
}
static int Partition(int[] Array,int low,int high){
int Pivot=Array[low];
int i=low;
int j=high;
while(i<j){
while (Array[i]<=Pivot) i++;
while (Array[j]>Pivot) j--;
if(i<j){
Swap(Array,i,j);
}
}
Swap(Array,j,low);
return j;
}
static void QuickSort(int []Array,int low,int high){
if(low<high){
int Pivot =Partition(Array,low,high);
QuickSort(Array,low,Pivot-1);
QuickSort(Array,Pivot+1,high);
}
}
static void PrintArray(int[] array){
for(Integer i :array){
System.out.print(" "+i+" ");
}
}
public static void main(String[] args){
int []Array={4,6,2,5,7,9,1,3};
int length=Array.length;
QuickSort(Array,0,length-1);
PrintArray(Array);
}
}