Refactor Heapsort to reuse array