priority queue clear method

后端 未结 6 1865
我在风中等你
我在风中等你 2020-12-29 18:35

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

6条回答
  •  执笔经年
    2020-12-29 19:01

    As any C++ STL reference will show you, the STL Priority Queue class does not have a function like 'clear' or 'erase'. http://www.cplusplus.com/reference/stl/priority_queue/

    It is a container class, and as such, a very simple destructor is generated by the compiler (in most cases). If your priority queue uses only locally-allocated information in its nodes, then this should work fine for clearing out the memory.

    However, if you have dynamically allocated memory for the information in your priority queue, you will need to manually create a 'clear'-like function.

    Hope this helps!

提交回复
热议问题