Implementing a heap-sort algorithm