说我有
std::set<classtype> set;
class classtype {
bool operator==(const classtype& ct) {
//..
}
};
//..
std::set<classtype>::iterator it = set.find(element);
Find 确实使用了类中的 == 运算符,对吗?
我的参考资料还说它有 log(n) 最坏情况运行时,其中 n 是集合中元素的数量。这在内部是如何实现的?我知道关键是集合中的元素有一个顺序(因此插入需要很长时间才能创建该顺序),对于整数集来说,顺序意味着什么很清楚,但对于随机类来说不是那么多。