Your organization has purchased a new parallel computer (or Solution #include \"
ID: 3656590 • Letter: Y
Question
Your organization has purchased a new parallel computer (orExplanation / Answer
#include "Heap.h" // header file for class Heap Heap::Heap() : size(0) { } // end default constructor Heap::~Heap() { } // end destructor bool Heap::heapIsEmpty() const { return bool(size == 0); } // end heapIsEmpty void Heap::heapInsert(const HeapItemType& newItem) // Method: Inserts the new item after the last item in the // heap and trickles it up to its proper position. The // heap is full when it contains MAX_HEAP items. { int numCom = 0; // place the new item at the end of the heap items[size] = newItem; // trickle new item up to its proper position int place = size; int parent = (place - 1)/2; while (numCom++, (parent >= 0) && (items[place].getKey() > items[parent].getKey()) ) { // swap items[place] and items[parent] HeapItemType temp = items[parent]; items[parent] = items[place]; items[place] = temp; place = parent; parent = (place - 1)/2; } // end while ++size; } // end heapInsert void Heap::heapDelete(HeapItemType& rootItem) // Method: Swaps the last item in the heap with the root // and trickles it down to its proper position. { rootItem = items[0]; items[0] = items[--size]; heapRebuild(0); } // end heapDelete void Heap::heapRebuild(int root) { // if the root is not a leaf and the root's search key // is less than the larger of the search keys in the // root's children int child = 2 * root + 1; // index of root's left // child, if any if ( childRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.