C++ priority_queue push()
 
 
 C++ priority_queue push()
 
  C++ Prioriy_queue push()函数用于将元素插入优先级队列。将元素添加到优先级队列容器中,然后将优先级队列的大小增加1、首先,将元素添加到后面,同时优先级队列的元素根据优先级对其自身进行重新排序。
 
语法
 
 将priority_queue'pq'视为priority_queue对象。
 
 
参数
 
  vlaue: 用于将值添加到优先级队列中。
 
返回值
 
 无
 
示例1 
 
 
 
  #include <iostream>
#include <queue>
using namespace std;
int main()
{
  priority_queue<char> mp;
mp.push('c');
mp.push('d');
mp.push('a');
mp.push('b');
mp.push('e');
cout<< "poping element ";
while(!mp.empty())
{
cout<< ' ' <<mp.top();
mp.pop();
}
return 0;
} 
   
  
  输出: 
 
 
示例2 
 
 
 
  #include <iostream>
#include <queue>
#include <string>
using namespace std;
int main()
{
 priority_queue<string> mp;
mp.push("my");
mp.push("india");
mp.push("Is");
mp.push("Great");
mp.push("Country");
cout<< "poping element: ";
while(!mp.empty())
{
cout<< ' ' <<mp.top();
mp.pop();
}
return 0;
} 
   
  
  输出: 
 
 
 
  poping element:  my india Is Great Country