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的更多相关文章
随机推荐
- [IOI 1994]数字三角形
数字三角形 总时间限制: 1000ms 内存限制: 65536kB 描述 73 88 1 02 7 4 44 5 2 6 5 (图1) 图1给出了一个数字三角形.从三角形的顶部到底部有很多条不同的路径 ...
- SpringBoot+Mysql 无法保存emoj表情?
尤记得很久以前,想存 emoj 表情到 mysql 中,需要额外的将 emoj 表情转码之后保存,每次读取时,再解码还原成一下:每次这种 sb 的操作,真心感觉心塞,那么有没有办法直接存呢? mysq ...
- eDiary
多年过去,您经历了BBS.论坛.博客.推特.微博 ...,但在电脑的某个 角落,eDiary始终为你守护发自你内心的声音. eDiary的作用不仅仅在于写日记,您也可以用它来记流水帐.写工作日志, 记 ...
- c++ 内存二进制表示
int a=1 string b="1" 1.其中变量a在内存中的二进制是 0000 0001 2.那么变量b是一个字符串,ascii码是49(字符串1的ascii码是49)通过计 ...
- DotnetSpider爬虫简单示例 net core
文章地址 https://blog.csdn.net/sD7O95O/article/details/78097556 安装爬虫框架 NUGET 安装DotnetSpider 创建HTTP协议数据包 ...
- html引入公共模块
如果没有母版页,那么大量相同布局的页面会有很多相同的代码,那么这就提到了一个概念,叫重用性:可以将相同布局的代码放在一个单独的文件,里面写一些公共模块,那么在其他页面只需要在指定位置引入他们就可以了写 ...
- 2019 哔哩哔哩java面试笔试题 (含面试题解析)
本人5年开发经验.18年年底开始跑路找工作,在互联网寒冬下成功拿到阿里巴巴.今日头条.哔哩哔哩等公司offer,岗位是Java后端开发,因为发展原因最终选择去了哔哩哔哩,入职一年时间了,也成为了面 ...
- 基于OpenGL的三维曲面动态显示实现
在使用Visual C++的MFC AppWizard建立应用程序框架后,生成了多个类,与OpenGL编程相关的类是视图类,主要的显示任务都在其中完成. 1.基于OpenGL绘图的基本设置 1.1 设 ...
- JS中判断对象是对象还是数组的方法
https://www.cnblogs.com/ma-shuai/p/7805264.html
- angular创建一个独立弹窗服务
1.说明: 这个服务用于创建一个modal(弹窗),通常下,这个弹窗会插入到body的底部,并且拥有自己的作用域($scope),也可以和外界通讯. 2.逻辑: (1).创建模版 (2).拿到模版里要 ...