Queues are an abstract data type, specifically designed to operate in a FIFO context (first-in-first-out). The elements are inserted into one end of the container and extracted from the other. They are a type of container adaptor in the C++ Standard Library. The queue::emplace()
is a method available in the STL which constructs and inserts an element into the queue.
Syntax:
queue_name.emplace(val);
Parameters: The queue::emplace()
method accepts a single parameter:
•Argument to construct a new element
Return value: none
Example of queue::emplace() method
#include <iostream> #include <queue> using namespace std; int main () { queue<int> q; for(int i = 1; i <= 5; i++) q.emplace(i); while (!q.empty()) { cout<<q.front()<<" "; q.pop(); } return 0; }
Output:
1 2 3 4 5