Open In App

unordered_set operator!= in C++ STL

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

The != is a relational operator in C++ STL which compares the equality and inequality between unordered_set containers. The Comparison is done in the following procedure: 

  1. First, the sizes are compared.
  2. Then, each element in one of the containers is looked for in the other.

Syntax: 

unordered_set1 != unordered_set2 

Parameters: This method takes the two unordered_set containers unordered_set1 and unordered_set2 as the parameters which are to be checked for equality.
Return Value: This method returns 

  • true: if both the unordered_set containers on the left and right of the operator are not equal.
  • false: if the unordered_set containers on the left and right of the operator are equal.

Below examples illustrate the != operator:
Example:

CPP




// C++ program to illustrate
// unordered_set operator!=
 
#include <cstring>
#include <iostream>
#include <unordered_set>
using namespace std;
 
int main()
{
    unordered_set<string>
        a = { "C++", "Java", "Python" },
        b = { "Java", "Python", "C++" },
        c = { "C#", "Python", "Java" };
 
    if (a != b) {
        cout << "a and b are not equal\n";
    }
    else {
        cout << "a and b are equal\n";
    }
 
    if (a != c) {
        cout << "a and c are not equal\n";
    }
    else {
        cout << "a and c are equal\n";
    }
 
    return 0;
}


Output: 

a and b are equal
a and c are not equal

 

Time complexity: O(N)


Last Updated : 05 Jun, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads