I searched and didn't find a way to do this, if it exists, can you guys help me how to do it?
1 Answer
Depending on your exact heap layout, you probably have two candidates (assuming that your root is the min element and the second layer are the max elements).
Choose the max one, and replace it with the last element of the heap - as with a regular heap - and perform a downward heap repair. Just as with a regular heap, starting at position 1 or 2 instead of 0, and going down to levels as you do in a min-max-heap.
2 Comments
lucasbibiano
Thanks, I tried to do exactly this at first, but there was a minor typo in my code.
Has QUIT--Anony-Mousse
@jwpat7 a min-max heap is not a min heap. It is for double-ended priority queues, and it does allow efficient retrieval of the maximum. en.wikipedia.org/wiki/Min-max_heap