C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

C++ priority_queue push()

C++ priority_queue push()

C++ Prioriy_queue push()函数用于将元素插入优先级队列。将元素添加到优先级队列容器中,然后将优先级队列的大小增加1、首先,将元素添加到后面,同时优先级队列的元素根据优先级对其自身进行重新排序。

语法

将priority_queue'pq'视为priority_queue对象。
pq.push (value);

参数

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;
}
输出:
poping element  e d c b a

示例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
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4