How to Check if a Deque is Empty in C++? Last Updated : 02 Apr, 2024 Comments Improve Suggest changes Like Article Like Report In C++, a deque is a container provided by the STL library that is similar to a queue. However, unlike queues, it allows insertion and deletion from both ends. In this article, we will learn how to determine whether a deque is empty or not in C++. Example: Input: myDeque = {2, 4, 6 } Output: dq1 is not Empty.Checking Whether a Deque is Empty in C++To check if a std::deque is empty or not in C++, we can use the std::deque::empty() member function which returns a boolean value true if the deque is empty and false if the deque is not empty. Syntax of std::deque::empty()dq_name.empty()C++ Program to Check if a Deque is EmptyThe below program demonstrates how we can check if a deque is empty or not in C++. C++ // C++ Program to demonstrates how we can check if a deque // is empty or not #include <deque> #include <iostream> using namespace std; int main() { // Initialize a deque with few elements deque<int> dq = { 1, 2, 3 }; // Check if deque is empty if (dq.empty()) { cout << "Deque is empty" << endl; } else { cout << "Deque is not empty" << endl; } // Delete elements from the deque dq.pop_back(); dq.pop_back(); dq.pop_back(); // Now check if a deque is empty or not cout << "After Removal: "; if (dq.empty()) { cout << "Deque is empty" << endl; } else { cout << "Deque is not empty" << endl; } return 0; } OutputDeque is not empty After Removal: Deque is empty Time Complexity: O(1)Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article How to Check if a Deque is Empty in C++? yuvrajghule281 Follow Improve Article Tags : C++ Programs C++ STL cpp-deque deque CPP Examples +2 More Practice Tags : CPPDequeSTL Similar Reads How to Check if a Set is Empty in C++? In C++, a set is an associative container that stores unique elements in a sorted order. In this article, we'll explore different approaches to check if a set is empty in C++ STL. Check if a Set is Empty or Not in C++To check if a std::set is empty in C++, we can use the std::set::empty() function. 2 min read How to Check if a Map is Empty in C++? In C++, a map is an associative container that stores elements as key-value pairs and an empty map means it contains no elements. In this article, we will learn how to check if a map is empty or not in C++. Example: Input: map<int,string>mp1 = {{1, "Ram"}, {2, "Mohit"}};map<int,string> m 2 min read How to Check if a List is Empty in C++? In C++, a list is a sequence container that allows non-contiguous memory allocation and is implemented using a doubly linked list. In this article, we will learn how to check if a list is empty in C++. Example: Input: myList = {1, 2, 3}; Output: List is not empty.Check if a List is Empty in C++To ch 2 min read How to Check if a Stack is Empty in C++? In C++, we have a stack data structure that follows a LIFO (Last In First Out) rule of operation. In this article, we will learn how to check if a stack is empty in C++. Example:Input:myStack = {1, 2, 3 } Output:Stack is not EmptyChecking if a Stack is Empty in C++To check if a stack is empty in C++ 2 min read How to Check if an Array is Empty in C++? In C++, arrays are fixed-size data structures that allow the users to store similar data in contiguous memory locations. In this article, we will learn how to check if an array is empty in C++. Example: Input:arr[]={}arr[]={1,2,3,4,5}Output:The array is emptyThe array is not emptyCheck if an Array i 3 min read Like