f********3 发帖数: 210 | 1 比如面试时,用set显然更好写。但hashset快。
hashset不是STL里面的,那么是不是所有的函数都得自己写。。。。感觉太麻烦了。。。
在这里看到个例子。那么面试时是不是还得这样写?
有没有好点的hashset的例子?多谢了
struct eqstr
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) == 0;
}
};
void lookup(const hash_set, eqstr>& Set,
const char* word)
{
hash_set, eqstr>::const_iterator it
= Set.find(word);
cout << word << ": "
<< (it != Set.end() ? "present" : "not present")
<< endl;
}
int main()
{
hash_set, eqstr> Set;
Set.insert("kiwi");
Set.insert("plum");
Set.insert("apple");
Set.insert("mango");
Set.insert("apricot");
Set.insert("banana");
lookup(Set, "mango");
lookup(Set, "apple");
lookup(Set, "durian");
} | S**I 发帖数: 15689 | 2 boost library
。。
【在 f********3 的大作中提到】 : 比如面试时,用set显然更好写。但hashset快。 : hashset不是STL里面的,那么是不是所有的函数都得自己写。。。。感觉太麻烦了。。。 : 在这里看到个例子。那么面试时是不是还得这样写? : 有没有好点的hashset的例子?多谢了 : struct eqstr : { : bool operator()(const char* s1, const char* s2) const : { : return strcmp(s1, s2) == 0; : }
|
|