set_multiset_functor
#include<iostream>
#include<string>
#include<set>
using namespace std; class Student
{
public:
Student(int age,string name)
{
m_age=age;
m_name=name;
} Student(const Student &stu)
{
m_age=stu.m_age;
m_name=stu.m_name;
cout << "Student "<<m_name<<","<<m_age<<endl;
} int m_age;
string m_name;
}; class stuFunctor{
public:
bool operator()(const Student &stu1,const Student &stu2)
{
return stu1.m_age>stu2.m_age;
}
}; void TestStudent()
{ set<Student,stuFunctor> setStudent;
//Student A(1,"aa"),B(2,"bb"),C(3,"cc");
//setStudent.insert(A);
//setStudent.insert(B);
//setStudent.insert(C);
setStudent.insert(Student(,"aa"));
setStudent.insert(Student(,"bb"));
setStudent.insert(Student(,"cc")); set<Student,stuFunctor>::iterator it;
for (it=setStudent.begin();it!=setStudent.end();++it)
{
cout<<it->m_name<<" ";
}
cout<<endl;
/*
Student aa,1
Student bb,2
Student cc,3
cc bb aa
请按任意键继续. . .
*/
} void TestFunctor()
{
int a[]={,,,,,};
//set<int,less<int>> setInt;
set<int,greater<int>> setInt;
for (int i=;i<;i++)
{
setInt.insert(a[i]);
setInt.insert(a[i]);
}
//set<int,less<int>>::iterator it;
set<int,greater<int>>::iterator it;
for (it=setInt.begin();it!=setInt.end();++it)
{
cout<<*it<<" ";
}
cout<<endl;
} void TestMultiSet()
{
int a[]={,,,,,};
multiset<int> setInt;
for (int i=;i<;i++)
{
setInt.insert(a[i]);
setInt.insert(a[i]);
}
multiset<int>::iterator it;
for (it=setInt.begin();it!=setInt.end();++it)
{
cout<<*it<<" ";
}
cout<<endl;
/*
1 1 2 2 3 3 4 4 5 5 6 6
请按任意键继续. . .
*/
} void main()
{
TestStudent();return;
TestFunctor();return;
TestMultiSet();return;
int a[]={,,,,,};
set<int> setInt;
for (int i=;i<;i++)
{
setInt.insert(a[i]);
setInt.insert(a[i]);
}
set<int>::iterator it;
for (it=setInt.begin();it!=setInt.end();++it)
{
cout<<*it<<" ";
}
cout<<endl; /*
1 2 3 4 5 6
请按任意键继续. . .
*/ }
set_multiset_functor的更多相关文章
随机推荐
- PatchMatchStereo可能会需要的Rectification
在稠密三维重建中,rectification可以简化patch match的过程.在双目特征匹配等场景中其实也用得到,看了一下一篇论文叫< A Compact Algorithm for Rec ...
- Ognl 语法基础教程
本文将力求用最简单的语言和实例,介绍一下 OGNL 的语法规则,文章主要内容参考自官方文档http://commons.apache.org/proper/commons-ognl/language- ...
- mongodb数据库操作 python+命令行
一.python操作 from bson.objectid import ObjectId import pymongo client1 = pymongo.MongoClient(host=) ...
- thinkphp伪静态怎么实现
thinkphp如何实现伪静态? 去掉 URL 中的 index.php ThinkPHP 作为 PHP 框架,是单一入口的,那么其原始的 URL 便不是那么友好.但 ThinkPHP 提供了各种机制 ...
- linux -------- 使用xshell ,winscp 连接linux 以及一些问题解决
1. 安装主要就是默认确定 2.连接VM上的centos 系统 设置连接模式 3.通过 ping 虚拟机上的linux系统的IP地址 4.使用xshell 进行连接 5.输入linux 的用户名和密码 ...
- 干货|Dubbo社区开发者日经验分享
Hello,各位小伙伴大家好,我是小栈君,昨天也就是2019年10月26日,有幸在成都参加了由阿里举办的"Dubbo社区开发者日". 本次活动汇聚了各方面的大神欢聚一堂,主要是对现 ...
- DDR3(5):读写仲裁
上一讲我们完成了读的控制,但是并不知道是否设计成功,必须读写结合才行.DDR3 的 app 端的命令总线是读写复用的,因此可能会存在读写冲突的时刻,为了解决此问题,必须进行分时读写,也就是我们说的仲裁 ...
- python docker api
开启Remote API docker默认是没有开启Remote API的,需要我们手动开启.编辑/lib/systemd/system/docker.service文件, 在文件里的ExecStar ...
- 常用Java API之Ramdom--用代码模拟猜数小游戏
常用Java API之Ramdom Ramdom类用来生成随机数字.使用起来也是三个步骤: 1.导包 import java.util.Random; 2.创建 Random r = new Rand ...
- FRP represents an intersection of two programming paradigms.
FRP represents an intersection of two programming paradigms. Functional programming Functional progr ...