// buildHeap(A,n) reorders A[0,...,n-1] so that it
  // statisfies the ordering requirement of a max-heap.

  void buildHeap(int A[], int n)
  {
    for(int i = parent(n-1); i >= 0; i--)
    {
      reheapDownMax(i, A, n);
    }
  }


 // heapSort(A, n) sorts A[0,...,n-1] into nondescending order.

  void heapSort(int A, int n)
  {
    buildHeap(A, n);
    k = n;
    while(k > 1)
    {
      swap(A[0], A[k-1]);
      k--;
      reheapDownMax(0, A, k);
    }
  }


내가 아는 힙정렬의 의미는 엉망인 array를 주면 내림차순이든 오름차순이든 정렬해주는걸로 알고 있소.

그런데 힙솔트 함수를 보면 빌드힙을 한번 해주고 들어가오.

그런데 빌드힙은 a 어레이를 이미 정렬을 해주오.

그럼 도대체 heapsort에서 하는일은 무엇이오?

왜 잘 정렬된 a 어레이를 스왑시켜서 엉망으로 만든뒤 다시 고쳐주고 그런일을 반복하는 이유가 뭐요?...

책과 구글링 코드가 다 이러니 오타는 아닐거고...