首页 > 其他 > 详细

set_map_二叉搜索树

时间:2014-01-15 08:42:01      阅读:406      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
/*
set:二叉搜索树维护集合的容器
map:维护键和键对应的值的容器
*/
#include<iostream>
#include<set>
#include<map>
#include<string>

using namespace std;

int main()
{
    set<int> s;

    s.insert(1);
    s.insert(5);
    s.insert(3);

    set<int>::iterator ite;

    ite = s.find(1);
    if (ite == s.end())cout << "not found";
    else cout << "found";

    //删除元素
    s.erase(1);

    //其它查找方式
    if (s.count(3) != 0)cout << "found";
    else cout << "not found";

    //遍历
    for (ite = s.begin(); ite != s.end(); ite++)
        cout << *ite << " ";

    map<int, const char*> m;

    m.insert(make_pair(1, "one"));
    m.insert(make_pair(10, "ten"));
    m[100] = "hundred";

    map<int, const char*>::iterator ite2;
    ite2 = m.find(1);//查找
    cout << ite2->second << endl;

    ite2 = m.find(2);
    if (ite2 == m.end())cout << "not found";
    else cout << ite2->second;

    cout << m[10];//其它写法

    m.erase(10);//删除

    //遍历
    for (ite2 = m.begin(); ite2 != m.end(); ite2++)
        cout << ite2->first << " " << ite2->second << endl;

    system("pause");
    return 0;
}
bubuko.com,布布扣

set_map_二叉搜索树

原文:http://www.cnblogs.com/littlehoom/p/3513921.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!