title: building a bottomUp heap
body: <p>im trying to do a heap bottom up construction from Psuedo code from my text book however the output im getting is not a correct heap im getting out 2 9 8 6 5 7</p>
  
  <p>anyone know where im going wrong(pseudo code is from a text book, and heap needs to be array)</p>
  
  <p>here is the PsuedoCode bottom up im working with</p>
  
  <pre><code>//constructs a heap from elements of a given array by bottom up algorithm
  //input an array H[1...n] of orderable items
  //output a heap H[1...n]
  
  for i&lt;- [n/2] downto 1 do
   k&lt;-i; v&lt;-H[k];
   heap&lt;-False
    while not heap and 2*k &lt;= n do
     j&lt;-2*k
     if(j&lt;n) //there are two children
      if H[j] &lt; H[j+1] j&lt;- j+1
     if v&gt;=h[j]
      heap = true
     else H[k]&lt;-H[j]  k&lt;-j
   H[k] &lt;-V
  </code></pre>
  
  <p>here is my code</p>
  
  <pre><code>package heapbottomup;
  
  import javax.swing.Spring;
  
  public class heapbottomup {
  public static void main(String args[]){
      int[] array = {2 ,9 ,7 ,6 ,5 ,8};
      BottomUp(array);
  }
  
  static int[] BottomUp (int[]array){
      int n = array.length-1;
  
      for(int i=(n/2);i&gt;=1;i--){
          int k =i;
          int v = array[k];
          boolean Heap = false;
  
          while(!Heap &amp;&amp; ((2*k)&lt;=n)){
              int j = 2*k;
              if (j&lt;n){
                  if(array[j]&lt;array[j+1]) j =j+1;
              }
              if(v&gt;=array[j]){
                  Heap=true;
              }
              else{
                  array[k]= array[j];
                  k=j;
              }
              array[k]=v;
          }//end while
  
      }//end for
      print(array);
      return(array);
  }
  
  
  static void print(int[]array){
      if(array==null){
          System.out.println("empty");
          return;
      }
      for(int i =0;i&lt;array.length;i++){
          System.out.print(array[i] + " ");
      }
      System.out.println();
  }//end print
  
  
  }
  </code></pre>