C++ Queue 库 - pop() 函数
描述
C++ 函数 std::queue::pop() 移除队列的最前面的元素并将队列的大小减一。
此成员函数有效地调用底层容器的 pop_front 成员函数。
声明
以下是 std::queue::pop() 函数形式 std::queue 头的声明。
C++98
void pop();
参数
None
返回值
None
时间复杂度
常数,即 O(1)
示例
以下示例显示了 std::queue::pop() 函数的用法。
#include <iostream>
#include <queue>
using namespace std;
int main(void) {
queue<int> q;
for (int i = 0; i < 5; ++i)
q.emplace(i + 1);
cout << "Contents of queue" << endl;
while (!q.empty()) {
cout << q.front() << endl;
q.pop();
}
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 −
Contents of queue 1 2 3 4 5

