Difference between priority queue and a heap

后端 未结 5 1326
我在风中等你
我在风中等你 2021-01-30 16:38

It seems that a priority queue is just a heap with normal queue operations like insert, delete, top, etc. Is this the correct way to interpret a priority queue? I know you can b

5条回答
  •  轮回少年
    2021-01-30 17:25

    Having a class with exactly the interface you need (just insert and pop-max?) has its advantages.

    • You can exchange the implementation (list instead of heap, for example) later.
    • Someone reading the code that uses the queue doesn't need to understand the more difficult interface of the heap data structure.

    I guess my question is whether having a collection of functions is equivalent to storing them in some class and using them through a class or just using the functions themselves.

    It's mostly equivalent if you just think in terms of "how does my program behave". But it's not equivalent in terms of "how easy is my program to understand by a human reader"

提交回复
热议问题