title: heapsort algorithm clarifications when sorting is actually done
body: <p>I have some question about heapsort and about the heap involved in that.</p>
  
  <ol>
  <li><p>when you build the meax-heap from an array, actually you build that heap a standalone object, or you just arrange the array to allow following the algorithm to build the heap to construct from that a max-heap?</p></li>
  <li><p>after you rearrange the array in the order that represents a a max-heap you want sort that array or produce another array sorted from the elements of that array. </p></li>
  </ol>
  
  <p>The algorithm to do that is:</p>
  
  <p>A -- is an array example: {5, 3, 17, 10, 19,84, 6, 22, 9}</p>
  
  <p>HEAPSORT(A)</p>
  
  <pre><code>1 BUILD-MAX-HEAP(A) 
  // here you rearrange the array to represent a max heap or
   you actually construct a maxheap from that?
  
  //a max heap array representation will be:
   {84, 22, 17, 10, 19, 5, 6, 3, 9}
  
   2 for i = A.length downto 2{
   3   exchange A[1] with A[i];
   4   A.heap-size = A.heap-size - 1; -- what this do in fact?
   5  MAX-HEAPIFY(A, 1);
  }
  </code></pre>
  
  <p>From my point of view it seems to actually create a heap of array A size (a max-heap actually).
  Then on what is done actually the iteration, aparently is over the array and MAX-HEAPIFY - now on a shrieked heap somehow .</p>
  
  <p>Can you clarify me with those things step by step?</p>