set用法
来源:互联网 发布:spss数据分析实例报告 编辑:程序博客网 时间:2024/05/17 02:45
set是一种集合容器.-所以采用迭代器进行访问
作用:保证每个元素都是独一无二的;
应用:插入、遍历、删除、搜索;
eg:
#include<iostream>#include<string>#include<cstring>#include<cstdio>#include<cstdlib>#include<set>using namespace std;set<int>a;int main(){ int n,x; while(cin>>n&&n) { //clear()清零a.clear();//insert()插入
for(int i=0;i<n;i++) { cin>>x; a.insert(x); } int len=a.size(); //iterator()顺序遍历 cout<<"len:"<<len<<endl; cout<<"顺序遍历"<<endl; set<int>::iterator s; for(s=a.begin();s!=a.end();s++) cout<<*s<<" "; cout<<endl; //reverse_iterator()反向遍历 cout<<"反向遍历"<<endl; set<int>::reverse_iterator t; for(t=a.rbegin();t!=a.rend();t++) cout<<*t<<" "; cout<<endl; //erase()删除 cout<<"please input the number that you want to delete:"<<endl; int tx; cin>>tx; a.erase(tx); set<int>::iterator s1; for(s1=a.begin();s1!=a.end();s1++) cout<<*s1<<" "; cout<<endl; //find()检索 cout<<"please input the number you want to find:"<<endl; cin>>tx; set<int>::iterator s2; s2=a.find(tx); if(s2!=a.end()) cout<<*s2<<endl; else cout<<"not find it!"<<endl; system("cls"); } }
阅读全文
0 0
- set&&<set> 用法整理
- set 用法
- set用法
- set 用法
- Set用法
- set用法
- set用法
- set用法
- SET XACT_ABORT 的用法
- SET NOCOUNT 的用法
- SET ANSI_NULLS的用法
- SET IDENTITY_INSERT的用法
- SET CONCAT_NULL_YIELDS_NULL的用法
- SET XACT_ABORT 的用法
- SET NOCOUNT 的用法
- .net get set用法
- 批处理SET用法
- SET命令的用法
- 窗体间和自定义控件的传值
- 树状数组入门
- JAR概念和jar命令
- 设计模式_享元模式(15)
- 启动Django服务让其他电脑可访问
- set用法
- [POJ3648] 参加婚礼
- hc-05蓝牙模块与arduino连接实现手机控制蓝牙智能小车
- python datetime.timedelta的日期计算
- jzoj 2017.10.07 模拟赛
- 3天学会TensorFlow | 香港科技大学
- 让孩子进阶中产的唯一路径是编程?
- 注解(Annotation)
- 深入理解Java:注解(Annotation)--注解处理器