zoukankan      html  css  js  c++  java
  • priority queue

    priority queue 是一个加上heap处理规则的queue,是一个容器适配器。

    缺省情况下以vector为底部容器

    重要的几个函数如下:

    template <class InputIterator>  
        priority_queue(InputIterator first, InputIterator last, const Compare& x)  
            : c(first, last), comp(x) { make_heap(c.begin(), c.end(), comp); }  
        template <class InputIterator>  
        priority_queue(InputIterator first, InputIterator last)  
            : c(first, last) { make_heap(c.begin(), c.end(), comp); }  
    
    
     // 返回优先级最高的元素  
        const_reference top() const { return c.front(); }  
      
        // 插入元素, 并调整heap  
        void push(const value_type& x)  
        {  
            __STL_TRY {  
                c.push_back(x); //利用底层元素将元素插入  
                // 详细分析见<stl_heap.h>,重新堆排序  
                push_heap(c.begin(), c.end(), comp);  
            }  
            __STL_UNWIND(c.clear());  
        }  
      
        // 弹出优先级最高的元素  
        void pop() {  
            __STL_TRY {  
                // 详细分析见<stl_heap.h>  
                pop_heap(c.begin(), c.end(), comp);  
                c.pop_back();  
            }  
            __STL_UNWIND(c.clear());  
        }  
  • 相关阅读:
    MVC身份验证及权限管理
    EasyPR--开发详解
    ASP.NET 安全认证
    将Excel导入到数据中
    ExtJS 4 树
    ExtJS 4 表单
    ExtJS 4 Grids 详解
    ExtJS 4 类系统
    第4章 类型基础 -- 4.1 所有类型都从System.Object派生
    随滚动条浮动的链接块层
  • 原文地址:https://www.cnblogs.com/daocaorenblog/p/5300617.html
Copyright © 2011-2022 走看看