Standard Template Library (STL) - std::queue::pop
std::queue::pop
public member function - 公開成員函數
1. std::queue::pop
void pop();
removes the first element - 刪除隊列的第一個元素。
Remove next element
刪除 queue
中前端的元素。
Removes the next element in the queue
, effectively reducing its size by one.
刪除 queue
中前端的元素,有效地將其大小減小一個。
The element removed is the oldest element in the queue
whose value can be retrieved by calling member queue::front
.
刪除的元素是 queue
中插入最早的元素,可以通過調用成員 queue::front
來檢索其值。
This calls the removed element’s destructor.
這將調用已刪除元素的析構函數。
This member function effectively calls the member function pop_front
of the underlying container object.
這個成員函數有效地調用底層容器對象的成員函數 pop_front
。
2. Parameters
none
3. Return value
none
4. Examples
4.1 std::queue::pop
//============================================================================
// Name : std::queue::push/pop
// Author : Yongqiang Cheng
// Version : Version 1.0.0
// Copyright : Copyright (c) 2019 Yongqiang Cheng
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream> // std::cin, std::cout
#include <queue> // std::queue
int main()
{
std::queue<int> queue_data;
int int_data;
std::cout << "Please enter some integers (enter 0 to end):\n";
do
{
std::cin >> int_data;
queue_data.push(int_data);
} while (int_data);
std::cout << "queue_data contains: ";
while (!queue_data.empty())
{
std::cout << ' ' << queue_data.front();
queue_data.pop();
}
std::cout << '\n';
return 0;
}
The example uses push
to add a new elements to the queue, which are then popped out in the same order.
該示例使用 push
將新元素添加到隊列中,然後以相同順序彈出。
Please enter some integers (enter 0 to end):
3
6
8
0
queue_data contains: 3 6 8 0
5. Complexity - 複雜度
Constant (calling pop_front
on the underlying container).
常量 (在底層容器上調用 pop_front
)。
6. Data races - 數據競爭
The container and up to all its contained elements are modified.
容器及其所有包含的元素均已修改。
7. Exception safety - 異常安全性
Provides the same level of guarantees as the operation performed on the underlying container object.
提供與對底層容器對象執行的操作相同級別的保證。
assignment [ə'saɪnmənt]:n. 任務,佈置,賦值
References
http://www.cplusplus.com/reference/queue/queue/pop/
https://en.cppreference.com/w/cpp/container/queue/pop