Heap and Sort Implementation