STL --C++语言新特性2
unordered_set
数据存储机构也是采用哈希表的方式结构操作,此外,std::unordered_set在插入时不会自动排序。
//unordered_set
#include <iostream>
#include <string>
#include <set>
#include <unordered_set>
using namespace std;
int main()
{
std::unordered_set<int> un_set;
un_set.insert(23);
un_set.insert(33);
un_set.insert(12);
un_set.insert(78);
un_set.insert(99);
cout << "\nunordered_set:" << endl;
for (auto it : un_set)
{
cout << it << endl;
}
cout << endl;
std::set<int> st;
st.insert(23);
st.insert(33);
st.insert(12);
st.insert(78);
st.insert(99);
cout << "\n" << endl;
for (auto it : st)
{
cout << it << endl;
}
cout << endl;
return 0;
}
关联容器:unordered_map
内部采用hash表结构,具备快速检索的功能。特性:关联性,无序性,map,唯一性
//unordered_map
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
typedef unordered_map<string, string> strmap;
strmap merge(strmap str1, strmap str2)
{
strmap temp(str1);
temp.insert(str2.begin(),str2.end());
return temp;
}
int main