forked from Krushna-Prasad-Sahoo/JavaCode-Hacktoberfest2021
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArraySort.java
More file actions
Latest commit
47 lines (42 loc) · 1.08 KB
/
Copy pathArraySort.java
File metadata and controls
47 lines (42 loc) · 1.08 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
40
41
42
43
44
45
46
47
importjava.util.*;
publicclassMain {
publicstaticvoidmain(String[] args) {
intarr[] = { 0, 1, 1, 0, 1, 2, 1, 2, 0, 0, 0, 1 };
// int arr[] = {0, 1, 2, 0, 1, 2};
intsize = arr.length;
System.out.print("Array Before Sorting.");
for(intx : arr){
System.out.print(x + " ");
}
System.out.print("Array After Sorting.");
arr = array_sort(arr, arr_size);
for(intx : arr){
System.out.print(x + " ");
}
}
publicstaticint[] array_sort(inta[], intsize)
{
intl = 0;
inth = size - 1;
intm = 0, temp = 0;
while (m <= h) {
if(a[m] == 0){
temp = a[l];
a[l] = a[m];
a[m] = temp;
l++;
m++;
}
elseif(a[m] == 1){
m++;
}
else {
temp = a[m];
a[m] = a[h];
a[h] = temp;
h--;
}
}
returna;
}
}