push
语法:
1 |
void push(const value_type& __x); |
push() 加入一个元素
源代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
/** * @brief Add data to the %queue. * @param x Data to be added. * * This is a typical %queue operation. * The time complexity of the operation depends on the underlying * sequence. */ void push(const value_type& __x) { try { c.push_back(__x); std::push_heap(c.begin(), c.end(), comp); } catch(...) { c.clear(); __throw_exception_again; } } |
测试代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
// 梁笔记 // https://zouzhongliang.com #include <iostream> #include <queue> using namespace std; int main() { priority_queue<int> Qi; Qi.push(1); Qi.push(2); Qi.push(3); Qi.push(4); Qi.push(5); cout<<"Qi优先队列元素个数:"<<Qi.size()<<endl; } |
测试结果
1 |
Qi优先队列元素个数:5 |