Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library


The C++ deque::operator> function is used to check whether the first deque is greater than the second deque or not. It returns true if the first deque is greater than the second deque, else returns false. deque::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 lexicographically greater than the contents of rhs, else returns false.

Time Complexity

Linear i.e, Θ(n).

Example:

In the below example, the deque::operator> function is used to check whether the first deque is greater than the second deque 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 {0, 10, 20};

  if (dq1 > dq2)
    cout<<"dq1 is greater than dq2.\n";
  else
    cout<<"dq1 is not greater than dq2.\n";

  if (dq1 > dq3)
    cout<<"dq1 is greater than dq3.\n";
  else
    cout<<"dq1 is not greater than dq3.\n";
    
  return 0;
}

The output of the above code will be:

dq1 is not greater than dq2.
dq1 is greater than dq3.

❮ C++ <deque> Library