Implementing a priority queue that can be iterated over in C++

后端 未结 4 1574
暗喜
暗喜 2021-02-10 07:23

I need to implement a priority queue for a project, but the STL\'s priority_queue is not indicated since we need to iterate over all elements and remove them random

4条回答
  •  一生所求
    2021-02-10 08:24

    Do you really need a priority queue ?

    You need iterate over all items and remove randomly -> linked list

    If you need to keep the list sorted, sort it at the beginning and then, when inserting new item, use insertion sort (insert new item on right place).

提交回复
热议问题