SORTING ARRAY OF 0 AND 1 WITH ONE LOOP WITH TEMP ARRAY

 /**  
 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]);  
 }  
 }  

Post a Comment

0 Comments