Heap sort, lifted from Active State