集合用途:用于频繁而快速的搜索,存入集合的内容会进行排序,所以查找速度快,复杂度为对数
std::set:存储的元素唯一, 不重复,默认我从小到大的排序
std::multiset:存储的元素可重复,默认我从小到大的排序
std::unordered_set:散列集合,使用散列函数计算唯一索引,并根据索引决定将元素放入哪个bucket(桶),
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;
/*定义一个模板函数,目的是为了方便打印不同类型的值*/
template <typename T1, typename T2>
void DisplayContent(const T1& input, const T2& vName) {
int index = 0;
if (input.empty()) {
cout << " " << vName << " is empty, the size = " << input.size() << endl;
return;
}
for (auto Iterator &