title: Why is my HeapSort skipping the first element in the array?
body: <p>Im implementing HeapSort for an assignment in my algorithms class, and Im finally done, but for some reason, the sort is skipping over the first element in my array. </p>
  
  <p>Original array: </p>
  
  <pre><code>int heapArray[SIZE] = {  5 ,99, 32, 4, 1, 12, 15 , 8, 13, 55 };
  </code></pre>
  
  <p>Output after HeapSort()</p>
  
  <pre><code>5 99 32 15 13 12 8 4 1
  </code></pre>
  
  <p>Iv gone through all the functions and cant figure out why its skipping the first element. Can anyone help me out? Iv included all the HeapSort functions below. I know its alot to look at, but im sooooo close.</p>
  
  <pre><code>int main()
  {
  int heapArray[SIZE] = {  5 ,99, 32, 4, 1, 12, 15 , 8, 13, 55 };
  HeapSort(heapArray);
  
  
  return 0;
  
  }
  </code></pre>
  
  <p>.........................................................................................</p>
  
  <pre><code>void HeapSort(int heapArray[])
  {   
  int heap_size = SIZE;
  int n = SIZE;
  int temp;
  
  Build_Max_Heap(heapArray);
  
  for(int i = n-1; i &gt;= 2; i--)
  {
      temp = heapArray[1];
      heapArray[1] = heapArray[i];
      heapArray[i] = temp;
  
      heap_size = heap_size-1;
      Max_Heapify(heapArray,1);
  }
  
  return;
  }
  </code></pre>
  
  <p>...........................................................................................</p>
  
  <pre><code>void Build_Max_Heap(int heapArray[])
  {
  double n = SIZE;
  
  for(double i = floor((n-1)/2); i &gt;= 1; i--)
  {
      Max_Heapify(heapArray,i);
  }
  
  return;
  }
  </code></pre>
  
  <p>...........................................................................................</p>
  
  <pre><code>void Max_Heapify(int heapArray[],int i)
  {
  int n = SIZE;
  int largest = 0;
  int l = Left(i);
  int r = Right(i);
  
  if(( l &lt;= n) &amp;&amp; (heapArray[l] &gt; heapArray[i]))
  {
      largest = l;
  }
  else
  {
      largest = i;
  }
  
  if( (r &lt;= n) &amp;&amp; ( heapArray[r] &gt; heapArray[largest]))
  {
      largest = r;
  }
  
  int temp;
  if(largest != i)
  {
      temp = heapArray[i];
      heapArray[i] = heapArray[largest];
      heapArray[largest] = temp;
  
      Max_Heapify(heapArray,largest);
  }
  
  return;
  }
  </code></pre>
  
  <p>...........................................................................................</p>
  
  <pre><code>int Parent(int i)
  {
  return (i/2);
  }
  
  int Left(int i)
  {
  return (2*i);
  }
  
  int Right(int i)
  {
  return ((2*i)+1);
  }
  </code></pre>