我认为heapSort1比heapSort2慢的原因,是因多了一个maxheap.insert函数,但是insert中存在一个向上排序(shiftUp函数),在插入完成后,也就意味着已经排序,成为最小堆,再进行一次最大堆的排序。
要是在insert函数中,取消‘’shiftUp(count+1)‘’,直接插入一个无序的,直接用shiftDown排序。
与heapSort2算法的效率的差异,是否存在此处?
void insert(Item item){
assert( count + 1 <= capacity );
data[count+1] = item;
//shiftUp(count+1);
count ++;
}4-5 基础堆排序和Heapify 中的疑问。请老师解答一下 @liuyubobobo