C++ queue push() Function
Example
Add elements to a queue:
queue<string> cars;
cars.push("Volvo");
cars.push("BMW");
cout << cars.front() << "\n";
cout << cars.back();
Definition and Usage
The push() function adds an element to the end (back) of a queue.
The new element becomes the last element. The first element stays the same, as you can see with front() in the example.
The push function is defined in the <queue> header file.
Syntax
queue.push(<type> value);
<type> refers to the type of the data that the queue contains.
Parameter Values
| Parameter | Description |
|---|---|
| value | Required. The value of the element to add. |
Technical Details
| Returns: | Nothing (void). |
|---|
Related Pages
Read more about queues in our Queues Tutorial.