C++ <deque> - emplace_front() Function
The C++ deque::emplace_front function is used to insert new element at the beginning of the deque, before the current first element. Each insertion of element increases the deque container size by one.
Syntax
template <class... Args> void emplace_front (Args&&... args);
Parameters
args |
Arguments forwarded to construct the new element. |
Return Value
None.
Time Complexity
Constant i.e, Θ(1).
Example:
In the example below, the deque::emplace_front function is used to insert new element at the beginning of the deque called MyDeque.
#include <iostream> #include <deque> using namespace std; int main (){ deque<int> MyDeque{10, 20, 30, 40, 50}; //insert a new element at the beginning of the deque MyDeque.emplace_front(1000); //insert a another new element at the beginning of the deque MyDeque.emplace_front(2000); //insert a another new element at the beginning of the deque MyDeque.emplace_front(3000); cout<<"MyDeque contains: "; for(int i=0; i< MyDeque.size(); i++) cout<<MyDeque[i]<<" "; return 0; }
The output of the above code will be:
MyDeque contains: 3000 2000 1000 10 20 30 40 50
❮ C++ <deque> Library