English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C++ The queue push() function is used to add a new element to the end of the queue. This function is used to perform insertion-related operations.
void push(const value_type& value);
value:This parameter indicates the value initialized for the element. It is the value of the new element to be added to the queue.
This function does not return a type, it only adds a new element to the queue.
#include <iostream> #include <queue> int main() { std::queue<int> newqueue; int qint; std::cout << "Enter some valid integer values (press 0 to exit)"; do { std::cin >> qint; newqueue.push(qint); } while (qint); std::cout << "newqueue contains: "; while(!newqueue.empty()) { std::cout << " " << newqueue.front(); newqueue.pop(); } return 0; }
Output:
Enter some valid integer values (press 0 to exit) 1 2 3 5 6 7 0 newqueue contains: 1 2 3 5 6 7 0
#include <iostream> #include <queue> using namespace std; int main() { queue<int> newqueue; newqueue.push(34); newqueue.push(68); while(!newqueue.empty()) { cout << " " << newqueue.front(); newqueue.pop(); } }
Output:
34 68
A single call to the push operation on the underlying container will be made.
The container and its elements have been modified.
Guarantees operations equivalent to those performed on the underlying container objects.