C++ Standard Library C++ STL Library

C++ <deque> - operator== Function



The C++ <deque> operator== function is used to check whether two deques are equal or not. It returns true if two deques are equal, else returns false. operator== compares elements of deques sequentially and stops comparison after first mismatch.

Syntax

template <class T, class Alloc>
bool operator== (const deque<T,Alloc>& lhs, const deque<T,Alloc>& rhs);
template <class T, class Alloc>
bool operator== (const deque<T,Alloc>& lhs, const deque<T,Alloc>& rhs);

Parameters

lhs First deque.
rhs Second deque.

Return Value

Returns true if the contents of lhs are equal to the contents of rhs, else returns false.

Time Complexity

Linear i.e, Θ(n).

Example:

In the example below, the operator== function is used to check whether two deques are equal or not.

#include <iostream>
#include <deque>
using namespace std;
 
int main (){
  deque<int> dq1 {10, 20, 30};
  deque<int> dq2 {10, 20, 30};
  deque<int> dq3 {10, 20};

  if (dq1 == dq2)
    cout<<"dq1 and dq2 are equal.\n";
  else
    cout<<"dq1 and dq2 are not equal.\n";

  if (dq1 == dq3)
    cout<<"dq1 and dq3 are equal.\n";
  else
    cout<<"dq1 and dq3 are not equal.\n";
    
  return 0;
}

The output of the above code will be:

dq1 and dq2 are equal.
dq1 and dq3 are not equal.

❮ C++ <deque> Library