C++-19-C++语言新特性2

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值