<legend id='rus7o'><style id='rus7o'><dir id='rus7o'><q id='rus7o'></q></dir></style></legend>

  • <small id='rus7o'></small><noframes id='rus7o'>

          <bdo id='rus7o'></bdo><ul id='rus7o'></ul>

      1. <tfoot id='rus7o'></tfoot>
      2. <i id='rus7o'><tr id='rus7o'><dt id='rus7o'><q id='rus7o'><span id='rus7o'><b id='rus7o'><form id='rus7o'><ins id='rus7o'></ins><ul id='rus7o'></ul><sub id='rus7o'></sub></form><legend id='rus7o'></legend><bdo id='rus7o'><pre id='rus7o'><center id='rus7o'></center></pre></bdo></b><th id='rus7o'></th></span></q></dt></tr></i><div id='rus7o'><tfoot id='rus7o'></tfoot><dl id='rus7o'><fieldset id='rus7o'></fieldset></dl></div>

        如何迭代priority_queue?

        How to iterate over a priority_queue?(如何迭代priority_queue?)

        <legend id='saB9L'><style id='saB9L'><dir id='saB9L'><q id='saB9L'></q></dir></style></legend>

                <bdo id='saB9L'></bdo><ul id='saB9L'></ul>

                  <small id='saB9L'></small><noframes id='saB9L'>

                    <tbody id='saB9L'></tbody>
                • <tfoot id='saB9L'></tfoot>
                • <i id='saB9L'><tr id='saB9L'><dt id='saB9L'><q id='saB9L'><span id='saB9L'><b id='saB9L'><form id='saB9L'><ins id='saB9L'></ins><ul id='saB9L'></ul><sub id='saB9L'></sub></form><legend id='saB9L'></legend><bdo id='saB9L'><pre id='saB9L'><center id='saB9L'></center></pre></bdo></b><th id='saB9L'></th></span></q></dt></tr></i><div id='saB9L'><tfoot id='saB9L'></tfoot><dl id='saB9L'><fieldset id='saB9L'></fieldset></dl></div>
                  本文介绍了如何迭代priority_queue?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我可以使用迭代器(如 vector)在 C++ 中遍历标准 priority_queue 或标准 queue 吗?我不想使用 pop,因为它会导致我的队列出队.

                  Can I traverse a standard priority_queue or standard queue in c++ with an iterator (like a vector)? I don't want to use pop because it cause my queue to be dequeued.

                  感谢您的帮助

                  推荐答案

                  priority_queue 不允许遍历所有成员,大概是因为太容易使队列的优先级排序无效(通过修改您遍历的元素)或者这可能是不是我的工作"的理由.

                  priority_queue doesn't allow iteration through all the members, presumably because it would be too easy in invalidate the priority ordering of the queue (by modifying the elements you traverse) or maybe it's a "not my job" rationale.

                  官方的解决方法是使用 vector 代替,并使用 make_heappush_heap 自己管理优先级pop_heap.在@Richard 的回答中,另一种解决方法是使用从 priority_queue 派生的类,并访问具有 protected 可见性的底层存储.

                  The official work-around is to use a vector instead and manage the priority-ness yourself with make_heap, push_heap and pop_heap. Another work-around, in @Richard's answer, is to use a class derived from priority_queue and access the underlying storage which has protected visibility.

                  这篇关于如何迭代priority_queue?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is the past-the-end iterator in STL C++?(STL C++ 中的最后迭代器是什么?)
                  vector::at vs. vector::operator[](vector::at 与 vector::operator[])
                  C++ equivalent of StringBuffer/StringBuilder?(C++ 等效于 StringBuffer/StringBuilder?)
                  Adding types to the std namespace(将类型添加到 std 命名空间)
                  Is the C++ std::set thread-safe?(C++ std::set 线程安全吗?)
                  How to use std::find/std::find_if with a vector of custom class objects?(如何将 std::find/std::find_if 与自定义类对象的向量一起使用?)
                  <i id='ZOvUJ'><tr id='ZOvUJ'><dt id='ZOvUJ'><q id='ZOvUJ'><span id='ZOvUJ'><b id='ZOvUJ'><form id='ZOvUJ'><ins id='ZOvUJ'></ins><ul id='ZOvUJ'></ul><sub id='ZOvUJ'></sub></form><legend id='ZOvUJ'></legend><bdo id='ZOvUJ'><pre id='ZOvUJ'><center id='ZOvUJ'></center></pre></bdo></b><th id='ZOvUJ'></th></span></q></dt></tr></i><div id='ZOvUJ'><tfoot id='ZOvUJ'></tfoot><dl id='ZOvUJ'><fieldset id='ZOvUJ'></fieldset></dl></div>
                • <tfoot id='ZOvUJ'></tfoot>
                    <tbody id='ZOvUJ'></tbody>
                    <bdo id='ZOvUJ'></bdo><ul id='ZOvUJ'></ul>

                          • <legend id='ZOvUJ'><style id='ZOvUJ'><dir id='ZOvUJ'><q id='ZOvUJ'></q></dir></style></legend>

                            <small id='ZOvUJ'></small><noframes id='ZOvUJ'>