C++ Standard Library C++ STL Library

C++ queue - operator>= Function



The C++ queue operator>= function is used to check whether the first queue is greater than or equal to the second queue or not. It returns true if the first queue is greater than or equal to the second queue, else returns false.

Syntax

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

Parameters

lhs First queue.
rhs Second queue.

Return Value

Returns true if the contents of lhs are lexicographically greater than or 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 the first queue is greater than or equal to the second queue or not.

#include <iostream>
#include <queue>
using namespace std;
 
int main (){
  queue<int> q1;
  queue<int> q2;
  
  for(int i = 0; i<3; i++) {
    q1.push(i);
    q2.push(i);
  }

  if (q1 >= q2)
    cout<<"q1 is greater than or equal to q2.\n";
  else
    cout<<"q1 is not greater than or equal to q2.\n";

  q2.pop();
  cout<<"\nAfter deleting first element of q2.\n";
  if (q1 >= q2)
    cout<<"q1 is greater than or equal to q2.\n";
  else
    cout<<"q1 is not greater than or equal to q2.\n";
    
  return 0;
}

The output of the above code will be:

q1 is greater than or equal to q2.

After deleting first element of q2.
q1 is not greater than or equal to q2.

❮ C++ <queue> Library