set函数和map函数
来源:互联网 发布:孔浩 java 编辑:程序博客网 时间:2024/05/29 05:55
set是使用二叉搜索树维护集合的容器,map是维护键和键对应的的值的容器。
#include<cstdio>#include<set>using namespace std;int main(){//声明 set<int> s;//插入元素 s.insert(1);s.insert(3);s.insert(5);//查找元素 set<int>::iterator ite;ite=s.find(1);if(ite==s.end())puts("not found");else puts("found");ite=s.find(2);if (ite==s.end())puts("not found");else puts("found");//删除元素。 s.erase(3);//其他的查找元素的方法if(s.count(3)!=0)puts("fount");else puts("not found");//遍历所有元素for(ite=s.begin();ite!=s.end();++ite) printf("%d\n",*ite); return 0;}
#include<cstdio>#include<map>#include<string>using namespace std;int main(){//声明(int为键,const char*为值)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 ite;ite= m.find(1);puts(ite->second);ite=m.find(2);if(ite==m.end())puts("not fount");else puts(ite->second);puts(m[10]);//删除元素 m.erase(10);//遍历所有元素 for(ite=m.begin();ite!=m.end();++ite)printf("%d: %s\n",ite->first,ite->second);return 0;}
0 0
- set函数和map函数
- map和set容器自定义比较函数
- List Set Map(集合函数)
- python map set函数用法
- Map函数和Reduce函数
- map()函数和reduce()函数
- STL中set、map的比较函数
- map及set中自定义比较函数
- STL map, multimap, set, multiset 函数介绍
- Map 和 Reduce函数
- day04_filtter() 和map函数
- Scala集合,序列(可变和不可变List),List各种函数的使用,不可变Set和可变Set,Map
- stl序列容器(map和set)的仿函数排序
- STL 笔记(二) 关联容器 map、set、multimap 和 multimap常用函数
- javescript循环(for…in…/Map和Set/函数/apply()与call()/map()/reduce()/filter()/sort())
- python的reduce函数和map函数
- python 的 map 函数 和 lambda函数
- Map Filter和Reduce函数
- WinCE上BINFS实现详解
- bzoj 3450(数学)
- PAT Basic1009
- Android Adapter操作Activity
- JAVA类与对象的初始化
- set函数和map函数
- Swift基础用法
- 【转载】浅谈java异常
- Listener 静态注册、与动态注册 --可以远程连接别的机器的DBServer
- 【KM匹配】 HDOJ 2448 Mining Station on the Sea
- YT14-HDU-洗牌的规律
- JQ前端方法容器
- 《JFrame类中paint()方法的重绘》
- VTK编译安装