练习题 No.17 set容器

来源:互联网 发布:黄金储备数据 编辑:程序博客网 时间:2024/06/06 03:13

要求

set容器是用二叉搜索书进行维护集合的容器。

限制条件

输入格式

输出格式

测试输入

测试输出

解题思路

还有可以重复的multiset

代码

#include <iostream>#include <set>using namespace std;  int main() {    set<int> s;     // 插入元素    s.insert(1);    s.insert(3);    s.insert(5);    set<int>::iterator it;    // 查找元素    it = s.find(1);    if (it == s.end()) {        cout << "No found" << endl;    } else {        cout << *it << endl;    }    // 删除    s.erase(3);    // 查找元素    cout << s.count(3) << endl;    for (it = s.begin(); it != s.end(); it++) {        cout << *it << endl;    }    return 0;  }
0 0
原创粉丝点击