5.1 Heapsort implementation