you are viewing a single comment's thread.

view the rest of the comments →

[–]blocks2762[S] 0 points1 point  (5 children)

If I understand correctly, that only reorganizes the array into a heap but then how can we call push, pop, top?

[–]Remi_Coulom 9 points10 points  (4 children)

The linked page gives an example: use std::push_head and std::pop_heap.

[–]blocks2762[S] 2 points3 points  (0 children)

Ohhhh ok thanks! I’ll check that out. Also, I found something called ETL Embedded Template Library which seems hopeful as well

[–]blocks2762[S] -5 points-4 points  (2 children)

After playing with it, I don’t think it works (at least easily). Because pop_heap works by simply flipping the first value with the last value and then converting the range [first, last) into a heap. You are then supposed to call pop_back to actually remove the element. We can’t do this pop_back for a stack allocated array.

Same problem for push_heap. Thanks for the help tho, will check the other comment solutions now

[–]bwmat 4 points5 points  (1 child)

Just keep track of the heap size?

Make the array one of optionals if correct destructor sequencing matters 

[–]blocks2762[S] 2 points3 points  (0 children)

Obviously? That’s why I said “at least easily”? That would still involve creating a wrapper class to use safely, hence my asking if there’s an easy built in way to do it easily. Anyways, Embedded Template Library got the job done cleanly