heapsort with template