implementation of heap sort; still fuzzy on the details, but it works