heapsort, working version