哈希查找,不需要排序,适用于精确查找,比二分查找更快

 

 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 }

 

相关文章:

  • 2021-10-13
  • 2021-07-13
  • 2021-08-14
  • 2022-03-04
  • 2022-12-23
  • 2022-12-23
  • 2021-07-23
  • 2022-01-30
猜你喜欢
  • 2022-03-07
  • 2022-12-23
  • 2022-12-23
  • 2021-06-26
  • 2021-08-23
  • 2021-07-09
  • 2021-10-05
相关资源
相似解决方案