priority_queue的成员函数

队列是提供先进先出顺序的数据结构。在删除数据时,选取队列中的第一个元素。但有时,应用程序需要用到队列修改后的一种版本,要求从队列中弹出数据 时能够按照队列元素优先级的顺序进行,而不是按照他们进入队列的顺序。这种数据结构叫做优先级队列。他在删除数据时,总是在数据元素中挑选优先级最大的那 个。每个元素的优先级是由一些外部标准确定的。

优先级队列的抽象模型并不把数据存储结构看成是顺序容器。元素在进入队列时没有任何限制,但在退出时却有一个标准。

STL标准模板库用priority_queue类来实现优先级队列ADT。数据类型T必须实现关系运算符 <  .

priority_queue

template,
    class Pred = less >
    class priority_queue {
public:
    typedef Cont::allocator_type allocator_type;
    typedef Cont::value_type value_type;
    typedef Cont::size_type size_type;
    explicit priority_queue(const Pred& pr = Pred(),
        const allocator_type& al = allocator_type());
    priority_queue(const value_type *first, const value_type *last,
        const Pred& pr = Pred(), const allocator_type& al = allocator_type());
    bool empty() const;
    size_type size() const;
    allocator_type get_allocator() const;
    value_type& top();
    const value_type& top() const;
    void push(const value_type& x);
    void pop();
protected:
    Cont c;
    Pred comp;
    };

posted on 2011-08-18 17:51  Goal  阅读(722)  评论(0编辑  收藏  举报

导航