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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top