C++ 哈希集用法

1. 头文件

#include  

2. 定义

unordered_set hashset;  

也可为其他类型,如:

unordered_set hashset;  

3.插入元素

hashset.insert('a')

4.删除元素

hashset.erase('a');

5.查询某元素是否存在

   if (hashset.count('a') > 0) 
   {
        return true;
   }
   else
   {
        return false;
   }

6.获取哈希集元素个数

hashset.size()

7.auto迭代

    for (auto it = hashset.begin(); it != hashset.end(); it++) 
    {
        cout << (*it) << " ";
    }

8.清空哈希集

  hashset.clear();

9.判断哈希集是否为空

   if (hashset.empty() ) 
   {
        return true;
   }
   else
   {
        return false;
   }

你可能感兴趣的:(C++,知识点,c++)