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

Deque Emplace Back Function

BLUF: Mastering Deque Emplace Back 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 Back Function

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

C++ emplace_back

The emplace_back method in C++ for deques appends a fresh element to the back of the deque, consequently enlarging the container's size by one.

Syntax

Example

void emplace_back(value_type val);

Parameter

val : Fresh data to be added at the conclusion of the deque.

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<int> d={1,2,3,4};
  deque<int>::iterator itr;
  d.emplace_back(5);
  for(itr=d.begin();itr!=d.end();++itr)
  std::cout << *itr <<" ";
  return 0;
}

Output:

Output

1 2 3 4 5

In this instance, the emplace_back method appends a new element, specifically the number 5, to the end of the deque.

Example 2

Let's see a simple example

Example

#include <iostream>
#include<deque>
using namespace std;
int main()
{
  deque<char> ch={'j','a','v'};
  deque<char>::iterator itr;
  ch.emplace_back('a');
  for(itr=ch.begin();itr!=ch.end();++itr)
  std::cout << *itr;
    return 0;
}

Output:

In this instance, the emplace_back method inserts a fresh element 'a' at the conclusion 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