English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C++ Usage and example of Deque emplace_front()

C++ Deque (Double-ended Queue)

C ++ The emplace_front() function of the deque container adds a new element at the beginning of the container, and the size of the container increases by one.

Syntax

void emplace_front(value_type val);

Parameter

valInsert a new value at the beginning of the deque.

Return value

It does not return any value.

Example1

Let's look at a simple example

#include<iostream>  
#include<deque>  
using namespace std;  
int main()
{
  dequefruit={"mango","banana"};
  deque::iterator itr;
  fruit.emplace_front("apple");
  fruit.emplace_front("strawberry");
  for(itr=fruit.begin();itr!=fruit.end();++itr)
  std::cout << *itr << "  ";
   return 0;
}

Output:

strawberry apple mango banana

In this example, the emplace_front() function adds two strings, apple and strawberry, to the beginning of the deque.

C++ Deque (Double-ended Queue)