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的更多相关文章
随机推荐
- AntDesign vue学习笔记(七)Form 读写与图片上传
AntDesign Form使用布局相比传统Jquery有点繁琐 (一)先读写一个简单的input为例 <a-form :form="form" layout="v ...
- day57——视图、模板渲染
day57 视图 网页:https://www.cnblogs.com/clschao/articles/10409764.html django官方文档:https://docs.djangopro ...
- 一、docker 入坑(win10和Ubuntu 安装)
前言 终究还是绕不过去了,要学的知识真的是太多了,好在我们还有时间,docker 之前只闻其声,不曾真正的接触过,现在docker 越来越火,很多公司也都开始使用了.所以对于我们程序员而言,又得修炼一 ...
- Java学习:常量和变量 的定义和注意事项
常量:在程序运行期间,固定不变的量. 常量的分类:1.字符串常量:凡是用双引号引起来的部分,叫做字符串常量. 例如:"abc","Hello","12 ...
- c# winform结合数据库动态生成treeview的父节点和子节点方法和思路
tb_food表的结构如图一: tb_foodtype表的结构如图二: //获取tb_foodtype表中的所有数据 private void InitDataTable() { SqlConnect ...
- C#写入Excel文件方式
由于在工作中经常要把数据库的统计数据导入Excel文件,进行IO磁盘操作,所以在这里记录下. 首先创建默认文件夹,并返回文件夹路径. private static string CPath(strin ...
- scp 基本用法(提高scp传输速度)
Outline spc 可以帮你实现: Linux Server 之间互传数据: Linux Server 和 Windows Server 之间互传数据: 参考: https://www.cnblo ...
- Java IO---字节流和字符流
一.IO流简介 流 流是一个抽象概念,Java程序和外部设备(可以是硬盘上的文件,也可以是网络设备)之间的输入输出操作是基于流的. 流就好比水管中的水流,具有流入和流出,类比数据的输入和输出. Jav ...
- 关于Mysql datetime类型存储范围测试
创建一个datetime表 > create table date_time(time datetime); > desc date_time; +-------+----------+- ...
- 使 WIN 10进入休眠、睡眠、关机的命令
1.用命令控制定时关机,重启,休眠等 休眠:rundll32.exe powrProf.dll,SetSuspendState 休眠:shutdown -h 睡眠:rundll32.exe powrp ...