English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C ++ The Queue pop() function is used to delete the first element of the queue.
void pop()
This function only performs deletion operations and does not accept any parameters.
This function does not return a value. It is used to delete elements.
#include <iostream> #include <queue> int main() { std::queue<int> newqueue; int qint; std::cout << "Enter some valid integer values (enter 0 to end)"; do { std::cin >> qint; newqueue.push(qint); } std::cout << "newqueue contains: "; while(!newqueue.empty()) { std::cout << " " << newqueue.front(); newqueue.pop(); } return 0; }
Output:
Enter some valid integer values (enter 0 to end) 1 3 4 5 6 7 0 The newqueue contains: 1 3 4 5 6 7 0
#include <iostream> #include <queue> using namespace std; int main() { { int a = 0; queue<int> newqueue; newqueue.push(4); newqueue.push(8); newqueue.push(12); newqueue.push(16); while(!newqueue.empty()) { newqueue.pop(); a++; } cout << a; } }
Output:
4
The complexity of the function is constant.
This function modifies the container and all its elements. After an element is removed from the queue, the corresponding positions of all other elements will also be modified.
It provides an equivalent guarantee for operations performed on underlying container objects.