STL set容器 入门
来源:互联网 发布:傲剑绿色版升级数据 编辑:程序博客网 时间:2024/06/06 14:26
1.头文件 : #include<set>
2.定义 : set<string>name;
3.存入 : name.insert(key);
4.输出 : 需要定义一个迭选器 方法如下
4.1 set<string>::iterator it;(定义it为迭选器)
4.2 for(it=name.begin();i!=name.end();ii++)
{
cout<<*it<<endl;
}
5.set容器默认从小到大排序 若需要自己定义的排序 需要进行重载
5.1 比较函数的重载
struct cmp{
bool operator()(string a,string b) / /对"()"进行重载
{
return a>b;
}
}
6.下面函数包括输入学生姓名 对学生姓名进行字典序排序的功能
#include <stdio.h>#include<algorithm>#include<string>#include<set>using namespace std;struct cmp{bool operator()(string a,string b){return a>b;} };int main(int argc, char *argv[]){int n;set<string,cmp>name;set<string,cmp>::iterator it;while(scanf("%d",&n)!=EOF){int i;for(i=0;i<n;i++){string c;cin>>c;name.insert(c);}for(it=name.begin();it!=name.end();it++){cout<<*it<<endl;}}return 0;}
阅读全文
0 0
- STL set容器 入门
- STL容器之set
- STL关联容器--Set
- STL容器:set,multiset
- STL中set容器
- STL中的set容器
- STL set map容器
- STL中的set容器
- STL set集合容器
- STL 之set容器
- STL容器之set
- C++--STL---set容器
- STL-set/multiset容器
- STL-set容器
- STL容器使用DEMO-set
- STL学习之set容器
- STL关联容器—set
- STL之set集合容器
- BZOJ1003(ZJOI2006)[物流运输]--最短路+DP
- Spark2.2任务提交运行机制及源码解析
- 被包含的页面,要与当前页<%@ page/>内容要一致,不允许contentType="text/html; charset=UTF-8",有空格
- java位移运算符
- Linux-shutdown命令
- STL set容器 入门
- datatables+java实现服务器端分页,排序,查询,列的显示影藏
- tp关于m的调用问题
- C语言实现词法分析器
- Maximum Subarray
- ios11 Handheld.PlayFullScreenMovie播视频不能跳过
- LINUX基础命令
- Android 自带阻尼效果的ScrollView,仿ios效果
- boundingbox回归