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

Deque Empty Function

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

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

C++ Deque empty

The empty function in C++ Deque verifies if the container is devoid of elements. It outputs 1 if the container is empty, and 0 if it contains elements.

Syntax

Example

void empty()

Parameter

It does not contain any parameter.

Return value

It does not return any value.

Example 1

Let's examine a basic scenario where the deque is not empty.

Example

#include <iostream>
#include<deque>
using namespace std;
int main()
{
    deque<int> first={5,6,7};
    if(first.empty())
    cout<<"Deque is empty";
    else
    cout<<"Deque is not empty";
    return 0;
}

Output:

Output

Deque is not empty

In this instance, the empty method confirms that the deque does not contain any elements, resulting in a return value of false.

Example 2

Let's see a simple example when deque is empty.

Example

#include <iostream>
#include<deque>
using namespace std;
int main()
{
    deque<int> d;
    if(d.empty())
    cout<<"Deque is empty";
    else
    cout<<"Deque is not empty";
    return 0;
}

Output:

Output

Deque is empty

In this instance, the empty method checks if the deque is devoid of elements. As a result, it will yield a true boolean value.

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