优先级队列清除方法 [英] priority queue clear method

查看:141
本文介绍了优先级队列清除方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从优先级队列中删除所有元素?这意味着如何销毁优先级队列?
高级感谢您的回答。是否有清除或擦除方法?

How do I delete all elements from a priority queue? That means how do I destroy a priority queue? advanced thanks for your answer. Is there any clear- or erase-like method?

推荐答案

priority_queue接口没有clear没有好的理由,我曾经能够辨别)。清除它的简单方法只是分配一个新的空队列:

The priority_queue interface doesn't have a clear() method (for no good reason I've ever been able to discern). A simple way to clear it is just to assign a new, empty queue:

priority_queue <int> q;
// use it
q = priority_queue <int>(); // reset it

这篇关于优先级队列清除方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆