Is it possible to make efficient pointer-based binary heap implementations?

前端 未结 6 1879
无人共我
无人共我 2020-12-14 12:22

Is it even possible to implement a binary heap using pointers rather than an array? I have searched around the internet (including SO) and no answer can be found.

T

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-14 12:50

    A binary heap is a complete binary tree obeying the heap property. That's all. The fact that it can be stored using an array, is just nice and convenient. But sure, you can implement it using a linked structure. It's a fun exercise! As such, it is mostly useful as an exercise or in more advanced datastructures( meldable, addressable priority queues for example ), as it is quite a bit more involved than doing the array version. For example, think about siftup/siftdown procedures, and all the edge cutting/sewing you'll need to get right. Anyways, it's not too hard, and once again, good fun!

提交回复
热议问题