forked from usamajay/hacktoberfest2021-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuickSort.java
80 lines (68 loc) · 1.07 KB
/
QuickSort.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
class QuickSort{
public static void main(String[]args){
int[] arrA = {8,5,10,3,9,2,1,11,4,6};
int[] arrB = new int[arrA.length];
int pivot = 0;
int x = 0;
int y = 0;
int mid = 0;
boolean cont = true;
while(cont){
pivot = arrA[0];
x=1;
y=0;
while(x<arrA.length){
if(arrA[x]<pivot){
arrB[y] = arrA[x];
y++;
}
x++;
}
arrB[y] = pivot;
mid = y;
x=1;
y++;
while(x<arrA.length){
if(arrA[x]>pivot){
arrB[y] = arrA[x];
y++;
}
x++;
}
for(int i=0; i<=mid; i++){
arrA[i] = arrB[i];
}
pivot = mid+1;
x = mid + 2;
y = mid+1;
while(x<arrB.length){
if(arrB[x]<pivot){
arrA[y] = arrB[x];
y++;
}
x++;
}
arrA[y] = pivot;
x = mid + 2;
y++;
while(x<arrB.length){
if(arrB[x]>pivot){
arrA[y] = arrB[x];
y++;
}
x++;
}
for(int i=0; i<arrA.length-1; i++){
if(arrA[i]>arrA[i+1]){
cont = true;
}
else{
cont = false;
}
}
}
for(int i=0; i<arrA.length; i++){
System.out.println(arrA[i]);
}
}
}