stl - What values are inserted in the set with this C++ code? -
i given interview question had following code. unfortunately, didn't right. explain code doing, commented line?
here code.
#include <iostream> #include <set> struct c { bool operator()(const int &a, const int &b) const { return % 10 < b % 10; } }; int main() { std::set<int> x({ 4, 2, 7, 11, 12, 14, 17, 2 }); std::cout << x.size(); std::set<int, c> y(x.begin(), x.end()); // not sure inserted in set std::cout << y.size() << std::endl; return 0; }
when run, x contains in order:
2 4 7 11 12 14 17
y contains in order:
11 2 4 7
my hunch set
reverses operator check equality (since set
contains unique values). unique values of a%10
exist.
Comments
Post a Comment