-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSort01.java
33 lines (31 loc) · 866 Bytes
/
Sort01.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
public class Main{
public static void main(String []args){
System.out.print("\nUnSorted 0 1 : ");
int[] a = {1,0,1,0,1,1,1,0,0,1,0,1};
for(int k=0; k<a.length; k++){
System.out.print(" "+a[k]);
}
int temp = 0;
int i = 0;
int j = a.length - 1;
while(i<j){
if(a[i]==1&&a[j]==1)
j--;
else if(a[i]==1&&a[j]==0){
temp = a[j];
a[j] = a[i];
a[i] = temp;
i++; j--;
}
else if(a[i]==0&&a[j]==1){
i++; j--;
}
else if(a[i]==0 && a[j]==0)
i++;
}
System.out.print("\n Sorted 0 1 : ");
for(int k=0; k<a.length; k++){
System.out.print(" "+a[k]);
}
}
}