HeapSort with thanks to Introduction to Algorithms - http://mitpress.mit.edu/books/introduction-algorithms