Data Str & Algorithm HW Solutions 38

Data Str & Algorithm HW Solutions 38 - 38 Chap. 5...

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

View Full Document Right Arrow Icon
38 Chap. 5 Binary Trees // Remove value at specified position template <class Elem, class Comp> bool minheap<Elem, Comp>::remove(int pos, Elem& it) { if ((pos < 0) || (pos >= n)) return false; // Bad pos swap(Heap, pos, --n); // Swap with last value while ((pos != 0) && (Comp::lt(Heap[pos], Heap[parent(pos)]))) swap(Heap, pos, parent(pos)); // Push up if large siftdown(pos); // Push down if small key it = Heap[n]; return true; } 5.20 Note that this summation is similar to Equation 2.5. To solve the summation requires the shifting technique from Chapter 14, so this problem may be too
Background image of page 1
This is the end of the preview. Sign up to access the rest of the 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