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的更多相关文章
随机推荐
- @Value注解无法为static 变量赋值
使用@Value给静态变量赋值时,出现空指针异常.经了解Spring 不允许/不支持把值注入到静态变量中.所以需要另一种方式为该变量赋值. 需要注意set方法也不要加static修饰符!
- C/C++ 的编译和链接
C/C++文件 C/C++程序文件包括 .h .c .hpp .cpp,其中源文件(.c .cpp)是基本的编译单元,头文件(.h .hpp)不会被编译器编译. C/C++项目构建(build)过程, ...
- Scala Type Parameters 2
类型关系 Scala 支持在泛型类上使用型变注释,用来表示复杂类型.组合类型的子类型关系间的相关性 协变 +T,变化方向相同,通常用在生产 假设 A extends T, 对于 Clazz[+T],则 ...
- 启动Sonar报错,ERROR: [1] bootstrap checks failed [1]: system call filters failed to install
错误提示信息: ERROR: [1] bootstrap checks failed[1]: system call filters failed to install; check the logs ...
- Python协程深入理解(转)
原文:https://www.cnblogs.com/zhaof/p/7631851.html 从语法上来看,协程和生成器类似,都是定义体中包含yield关键字的函数.yield在协程中的用法: 在协 ...
- Python批量更改文件名
一.问题在处理文件或者一些其他信息的时候我们需要更改文件名,那么我们可以写一个程序来修改这些文件名,以减少我们重复的做一件事. 二.解决本次使用的Python,利用的是Python中的OS模块,具体操 ...
- K8S学习笔记之Kubernetes 配置管理 ConfigMap
0x00 概述 很多情况下我们为某一应用做好镜像,当我们想修改其中的一些参数的时候,就变得比较麻烦,又要重新制作镜像,我们是不是有一种方式,让镜像根据不同的场景调用我们不同的配置文件呢,那我们就需要用 ...
- Java之利用Freemarker模板引擎实现代码生成器,提高效率
https://blog.csdn.net/huangwenyi1010/article/details/71249258 java模板引擎freemarker代码生成器 更多 个人分类: 一步一步 ...
- efCore+Mysql+Net Core
1.首先新建一个空的Asp.net core项目 2.新建一个类 gj.cs public class gj { // <summary> /// 主键 /// </summa ...
- Vert.x Web
https://vertx.io/docs/vertx-web/java/ Vert.x-Web是一组用于使用Vert.x构建Web应用程序的构建块.将其视为瑞士军刀,用于构建现代,可扩展的网络应用程 ...