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

后端 未结 4 1481
暗喜
暗喜 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:19

    STL's set should be usable to make what you want, although I must note that the list of requirements looks a little strange. You could just define a new type.

    template class impl_type = std::set> class prio_queue {
        typedef impl_type set_type;
        typedef typename set_type::iterator iterator;
        // etc
    public:
        // Forward the set's members
        T& top() {
            return *begin();
        }
        // etc
    };
    

提交回复
热议问题