STL优先队列重载

priority_queue默认是大根堆,如果需要使用小根堆,如下

int main(){
    priority_queue<int,vector<int>,greater<int> >que;
    while(1){
            int x=read();
            que.push(x);
            if(x==-1){
                while(!que.empty()) {
                    cout<<que.top()<<" ";
                    que.pop();
                }
            }
    }
    return 0;
}
posted @ 2017-05-24 21:17  江南何采莲  阅读(414)  评论(0)    收藏  举报