Deque Emplace Front Function - C++ Programming Tutorial
C++ Course / STL Queue & Stack / Deque Emplace Front Function

Deque Emplace Front Function

BLUF: Mastering Deque Emplace Front Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Deque Emplace Front Function

C++ is renowned for its efficiency. Learn how Deque Emplace Front Function enables low-level control and high-performance computing in the tutorial below.

The emplace_front function in C++ for deques inserts a new element at the front of the deque container, consequently expanding the container's size by one.

Syntax

Example

void emplace_front(value_type val);

Parameter

A value is to be added at the start of the deque for insertion.

Return value

It does not return any value.

Example 1

Let's see a simple example

Example

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

Output:

Output

strawberry apple mango banana

In this instance, the emplace_front method inserts two strings, specifically "apple" and "strawberry", at the start of the deque.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience