set 的应用
来源:互联网 发布:金山毒霸数据恢复 编辑:程序博客网 时间:2024/06/05 05:33
一直觉得编程中没有用到set的地方,今天碰到一道,傻眼了,学习一下吧
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 ()
{
}
- SET的应用
- set 的应用
- set函数的应用
- set的应用
- set的应用
- set的简单应用
- linux set 命令的应用
- multimap和set的应用
- STL Set的综合应用
- Oracle Set命令的应用
- 营业额统计 set的应用
- 有关set的一点应用
- POJ-3481(set的应用)
- ABAP中Set Country的应用
- COJ 1239集合set的简单应用
- STL应用——神奇的set
- POJ-3588(Set的应用)
- 220. Contains Duplicate III set的应用
- 并查集
- 完善discuz的@圈人功能
- Struts2中的Action
- Android的jni实例
- jQuery事件函数传递参数
- set 的应用
- js闭包
- POJ 1330 Nearest Common Ancestors (LCA)
- iOS 单件:只保留一个实例
- QT出现Driver not loaded的问题及解决办法
- java解析xml的几种方式
- 中英文颜色对照表(转载)
- discuz后台管理增加新导航/新单页
- vsftpd配置详解