user3601101
user3601101

Reputation: 3

Is it possible to use a min heap as a max heap?

I've implemented a minHeap class so I am curious if, without modifying the code, it would be possible to use the minHeap class as a max heap?

Upvotes: 0

Views: 93

Answers (1)

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272687

Just flip the sign of all your values before you put them into the heap, and again as you take them out of the heap.

Upvotes: 1

Related Questions