Implementation of heap sort