The CPP queue push function is used to add new elements to the back of the queue. The push function is used to insert a new element at the end of the queue. This function can only insert elements at the end, hence it is necessary to use the pop function to remove elements from the front of the queue.
Here are a couple of examples of how to use the push function in CPP:
Example 1:
#include #include
using namespace std;
int main() { queue q;
q.push(10); q.push(20); q.push(30);
cout << "The queue is : "; while (!q.empty()) { cout << q.front() << " "; q.pop(); } return 0; }
In this example, we have a queue with integer values. We use the push function to add three elements to the queue. We then use a while loop to print out the elements in the queue by using the front() function.
cout << "The queue is : "; while (!names.empty()) { cout << names.front() << " "; names.pop(); } return 0; }
In this example, we have a queue with string values. We use the push function to add three elements to the queue. We then use a while loop to print out the elements in the queue by using the front() function.
The CPP queue push function is included in the Standard Template Library (STL), which is a part of the CPP Standard Library. Therefore, no additional package library is required.
C++ (Cpp) queue::push - 30 examples found. These are the top rated real world C++ (Cpp) examples of queue::push extracted from open source projects. You can rate examples to help us improve the quality of examples.