课後辅导

5.6.3 Insertion into a Max Heap void MaxHeap::Push(int e) { if (heapSize+1 == capacity) Resize(); int currentNode = heapSize + 1; while (currentNode != 1 heap[currentNode/2] e) { heap[currentNode] = heap[currentNode / 2]; currentNode /= 2; } heap[currentNode] = e; } 5.6.4 Deletion from a Max Heap Example: delete from the heap 20 15 5 14 10 2 1 2 3 4 5 6 7 currentNode: The element to be popped: 1 20 2 15 15 2 2 14 14 2 4 5.6.4 Deletion from a Max Heap int MaxHeap::Pop(int e) { if (IsEmpty()) throw

文档评论(0)

1亿VIP精品文档

相关文档