C++ 容器set与multiset
来源:互联网 发布:js checkbox 选中事件 编辑:程序博客网 时间:2024/06/08 08:49
1,set的含义是集合,它是一个有序的容器,里面的元素都是排序好的,支持插入,删除,查找等操作,就
2,Set中的元素可以是任意类型的,但是由于需要排序,所以元素必须有一个序,即大小的比较关系,比如
3,自定义比较函数;
4,set的基本操作:
begin()
clear()
count()
empty()
end()
equal_range()
erase()
find()
get_allocator() 返回集合的分配器
insert()
lower_bound()
key_comp()
max_size()
rbegin()
rend()
size()
swap()
upper_bound()
value_comp()
5,自定义比较函数:
For example:
#include<iostream>
#include<set>
using namespace std;
typedef struct {
int a,b;
char s;
}newtype;
struct compare
{
bool operator()(const newtype &a, const newtype &b) const
{
return a.s<b.s;
}
};//the “; ”
set<newtype,compare>element;
int main()
{
newtype a,b,c,d,t;
a.a=1; a.s='b';
b.a=2; b.s='c';
c.a=4; c.s='d';
d.a=3; d.s='a';
element.insert(a);
element.insert(b);
element.insert(c);
element.insert(d);
set<newtype,compare>::iterator it;
for(it=element.begin(); it!=element.end();it++)
cout<<(*it).a<<" ";
cout<<endl;
for(it=element.begin(); it!=element.end();it++)
cout<<(*it).s<<" ";
}
element自动排序是按照char s的大小排序的;
6.其他的set构造方法;
#include <iostream>
#include <set>
using namespace std;
bool fncomp (int lhs, int rhs) {return lhs<rhs;}
struct classcomp {
};
int main ()
{
}
- c++set和multiset容器
- 容器set与multiset探秘
- C++ 容器set与multiset
- C++::STL::容器类::set/multiset
- 关联容器之set与multiset
- set和multiset容器
- STL容器:set,multiset
- set,multiset容器类型
- 容器set和multiset
- set,multiset容器类型
- 容器set和multiset
- set和multiset容器
- set/multiset容器
- STL-set/multiset容器
- Set和multiset容器
- C++:关联容器(set,multiset,map,multimap)
- C++/STL关联容器-集合-multiset&set的用法
- C++STL学习(4)容器set和multiset
- 使用junit测试service执行成功,数据库没有改变
- Java程序员集合框架面试题
- android Bitmap的一些操作
- 文件的下载与保存,以及mp3文件的播放
- UISearchBar和UISearchDisplayController
- C++ 容器set与multiset
- Linux查看内存和清理内存命令
- android 集成IDE(Eclipse) 的常用快捷键
- Android内核剖析--OOM killer
- Delete Contacts——滑动删除或批量删除通讯录中联系人的收费越狱插件
- hdu 4661 Message Passing(树形dp)
- 华为s5700acl设置
- 编译和链接
- firefox异步加载页面乱码处理。