C++ deque push_front() Function
Example
Add an element at the beginning of a deque:
deque<string> cars = {"Volvo", "BMW", "Ford", "Mazda"};
cars.push_front("Tesla");
for (string car : cars) {
cout << car << "\n";
}
Definition and Usage
The push_front() function adds an element to the beginning of a deque. The new element becomes the first element.
The push_front function is defined in the <deque> header file.
Syntax
deque.push_front(<type> value);
<type> refers to the type of the data that the deque contains.
Parameter Values
| Parameter | Description |
|---|---|
| value | Required. The value of the element to add. |
Technical Details
| Returns: | Nothing (void). |
|---|
Related Pages
Read more about deques in our Deque Tutorial.