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


The C++ queue::operator!= function is used to check whether two queues are unequal or not. It returns true if two queues are not equal, 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 not equal to the contents of rhs, else returns false.

Time Complexity

Linear i.e, Θ(n).

Example:

In the below example, the queue::operator!= function is used to check whether two queues are unequal 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 and q2 are not equal.\n";
  else
    cout<<"q1 and q2 are equal.\n";

  q1.pop();
  cout<<"\nAfter deleting first element of q1.\n";
  if (q1 != q2)
    cout<<"q1 and q2 are not equal.\n";
  else
    cout<<"q1 and q2 are equal.\n";
    
  return 0;
}

The output of the above code will be:

q1 and q2 are equal.

After deleting first element of q1.
q1 and q2 are not equal.

❮ C++ - Queue