2

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 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I tried to do exactly this at first, but there was a minor typo in my code.
@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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.