public static void buildAltHeap(int[] heap,int[] altheap,int n)
 {
    int i=0,j,l=0,c,temp;
    
    while(i<n)
    { 
        
       if(l%2==0)
       {
         c=i+(int)Math.pow(2,l);
        if(c<=n)       
        {
          for(j=i;j<c;j++)
         {
           
           altheap[j]=heap[min(heap,n-i)];
           temp=heap[min(heap,n-i)];
           heap[min(heap,n-i)]=heap[n-i-1];
           heap[n-i-1]=temp;
           
           i++;
         }  
         
        l++;
        }
        else
       {
          for(j=i;j<n;j++)
         {
           
           altheap[j]=heap[min(heap,n-i)];
           temp=heap[min(heap,n-i)];
           heap[min(heap,n-i)]=heap[n-i-1];
           heap[n-i-1]=temp;
           
           i++;
         }  
         
        l++;
       }
       }
          
       
       if(l%2!=0)
       {
         c=i+(int)Math.pow(2,l);
         if(c<=n)
         {     
         for(j=i;j<c;j++)
         {
           altheap[j]=heap[max(heap,n-i)];
           temp=heap[max(heap,n-i)];
           heap[max(heap,n-i)]=heap[n-i-1];
           heap[n-i-1]=temp;
           
           i++;
         }  
          l++;
         }
       
        else
        {     
         for(j=i;j<n;j++)
         {
           altheap[j]=heap[max(heap,n-i)];
           temp=heap[max(heap,n-i)];
           heap[max(heap,n-i)]=heap[n-i-1];
           heap[n-i-1]=temp;
           
           i++;
         }  
          l++;
         }
       }   
    }    
 }