Your written description doesn't ever actually outline the algorithm for making a max heap in the first place. It does demonstrate the algorithm via example, but trying to reverse-engineer the algorithm from that is difficult.
Also neither your description nor example discusses decreasing the heap size when actually sorting.
PS. In your completed example, the heapSize variable is redundant and literally identical to the for loop iterator. You could also pull out a very simple swapPlaces function to clean things up a tiny bit.
PPS. This was a really fun exercise and definitely helped me learn how heap sort works. (And has renewed my curiosity in understanding smoothsort.)
Your written description doesn't ever actually outline the algorithm for making a max heap in the first place. It does demonstrate the algorithm via example, but trying to reverse-engineer the algorithm from that is difficult.
Also neither your description nor example discusses decreasing the heap size when actually sorting.
PS. In your completed example, the
heapSize
variable is redundant and literally identical to thefor
loop iterator. You could also pull out a very simpleswapPlaces
function to clean things up a tiny bit.PPS. This was a really fun exercise and definitely helped me learn how heap sort works. (And has renewed my curiosity in understanding smoothsort.)