{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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 <class Elem, class Comp> bool minheap<Elem, Comp>::removemin(Elem& 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

{[ snackBarMessage ]}

Ask a homework question - tutors are online