-
set
基于红黑树实现,可以进行去重和排序操作。O(logn)。
一些常用的函数有:s.insert(x);
s.erase(x);
s.size();
s.find(x);
s.count(x); //因为有去重性质,count()统计出现的次数要么是0,要么是1,可以替代find()
s.empty(); -
unordered_set
O(1)。
一些常用的函数:s.insert();
s.erase();
s.find();
s.count();
s.empty(); -
map<string, int>
一种键值对的映射关系,内部存储结构是pair<first, second> 。[first-key,second-value]。前面的元素字典序排列
一些常见操作函数:m.size();
m.insert(pair);
m.find(key);
m.count(key);
m.erase(key);
m[key] = value; -
unordered_map<key, value>
无序版的map。
一些常用的操作函数:m.size();
m.insert(pair);
m.find(key);
m.count(key);
m.erase(key);
m[key] = value;
迭代器
for (auto it = m.begin(); it != m.end(); it ++ )
{
cout << it->first << " " << it->second << endl;
}