I want to compare two sets using the equal
algorithm but it's giving me an error.
How is it possible to know if two sets are equal or not?
if(equal (a.begin(), a.end(), v.begin(), v.end())
Two sets A and B are equal if they have exactly the same elements. We write A = B. Two sets A and B are equivalent if n(A)= n(B). Another way of saying this is that two sets are equivalent if they have the same number of elements.
The '==' is an operator in C++ STL performs equality comparison operation between two unordered sets and unordered_set::operator== is the corresponding operator function for the same. Parameters: This operator function takes reference of two unordered sets uset1 and uset2 as parameters which are to be compared.
The answer is quiet simple we can directly compare two maps by equivalence relational operator("=="), just like we compare two variables.
You can simply say a == v
, or perhaps . It's as efficient as it can be. a.size() == v.size() && a == v
(The latter form with the explicit size check may be better because set iterators aren't random-access.) Update: The size check is implied [thanks @juanchopanza!]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With