/**
sorting Array of 0s and 1s with Single Loop with help of
temporary array.
*/
class OneLoopSort
{
public static void main(String[]args)
{
int a[]={1,0,1,0,1,0};
int []t={1,1,1,1,1,1};
int j=0;
for(int i=0;i<a.length;i++)
{
if(a[i]==0)
{
t[j++]=0;
}
}
a=t;
for(int i=0;i<a.length;i++)
System.out.println(a[i]);
}
}
0 Comments