哈希查找,不需要排序,适用于精确查找,比二分查找更快
1 #define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS 2 #include <iostream> 3 #include <hash_set> 4 5 int main() 6 { 7 std::hash_set<const char *>hs;//哈希 8 9 hs.insert("china"); 10 hs.insert("abc"); 11 12 auto pfind = hs.find("china"); 13 14 if (pfind == hs.end()) 15 { 16 std::cout << "没有找到" << std::endl; 17 } 18 else 19 { 20 std::cout << *pfind << std::endl; 21 } 22 23 return 0; 24 }