priority queue clear method

后端 未结 6 1880
我在风中等你
我在风中等你 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:04

    there is no clear method supported for priority_queue in c++ but, this below is a good method to clear the priority_queue and has O(log(n)) time

    while (!pq.empty())
          pq.pop();
    

提交回复
热议问题