📅  最后修改于: 2023-12-03 15:29:50.531000             🧑  作者: Mango
Multiset is a container in C++ STL (Standard Template Library) that stores elements in a sorted order. It is implemented using a balanced binary tree, specifically the red-black tree. The multiset container is similar to the set container, with the difference that the multiset container allows duplicate elements.
The operator!=() function is a member function of the multiset container that is used to compare two multiset containers. It returns true if the two multiset containers are not equal and false otherwise.
The syntax for the operator!=() function is as follows:
bool operator!=(const multiset& other) const;
Here, other
is the multiset container to be compared with. The function returns a boolean value. If the multiset containers are not equal, the function returns true. If they are equal, the function returns false.
Consider the following code snippet:
#include <iostream>
#include <set>
int main()
{
std::multiset<int> set1{1, 2, 3};
std::multiset<int> set2{3, 2, 1};
std::multiset<int> set3{1, 2, 3, 4};
std::cout << std::boolalpha;
std::cout << (set1 != set2) << std::endl; // Outputs false
std::cout << (set1 != set3) << std::endl; // Outputs true
return 0;
}
In this example, we create three multiset containers set1
, set2
, and set3
. We then use the operator!=() function to compare these multiset containers. The output of the program is as follows:
false
true
This is because set1
and set2
have the same elements, but in a different order, whereas set1
and set3
have different number of elements.
The operator!=() function is a useful member function of the multiset container that allows us to compare two multiset containers. It returns true if the two containers are not equal and false otherwise.