deque::empty
deque::empty is used to check whether the deque container is empty or not. It does not change anything in the container.
Syntax:
empty();
Header File:
<deque>
Exceptions: It never throws any exception
Iterator Validity: Iterator Validity does not change in this container.
Example:
C++
// C++ program to implement deque::empty #include <deque> #include <iostream> using namespace std; int main() { // Declaration of Deque deque< int > GFG = { 1, 3, 6, 0, 0 }; if (GFG.empty() == true ) { cout << "The deque is empty" << endl; } else { cout << "The deque is not empty" << endl; } return 0; } |
Output
The deque is not empty
- Time Complexity – O(1)
- Space Complexity – O(1)
Difference Between deque::assign and deque::empty in C++
Deque or Double-ended queues are sequence containers with the feature of expansion and contraction on both ends. They are similar to vectors, but are more efficient in the case of insertion and deletion of elements at the end, and also the beginning. Unlike vectors, contiguous storage allocation may not be guaranteed.
Here we will see the difference between deque::assign and deque::at in C++.
Contact Us