Data Str & Algorithm HW Solutions 37

Data Str & Algorithm HW Solutions 37 - curr =...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
37 swap(Heap, pos, j); pos = j; // Move down } } template <class Elem, class Comp> if (n >= size) return false; // Heap is full int curr = n++; Heap[curr] = val; // Start at end of heap // Now sift up until curr’s parent < curr (Comp::lt(Heap[curr], Heap[parent(curr)]))) { swap(Heap, curr, parent(curr));
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: curr = parent(curr); } return true; } template &lt;class Elem, class Comp&gt; bool minheap&lt;Elem, Comp&gt;::removemin(Elem&amp; it) { if (n == 0) return false; // Heap is empty swap(Heap, 0, --n); // Swap max with last value if (n != 0) siftdown(0); // Siftdown new root val it = Heap[n]; // Return deleted value return true; }...
View Full Document

This note was uploaded on 12/27/2011 for the course MAP 2302 taught by Professor Bell,d during the Fall '08 term at UNF.

Ask a homework question - tutors are online