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的更多相关文章
随机推荐
- Linux重启Mysql命令
- K-Means 聚类分析学习笔记
在之前分享的链家二手房数据分析的练习中用到了 K-Means 聚类分析方法,所以就顺道一起复习一下 K-Means 的基础知识好了. K-Means 聚类分析可将样本分为若干个集群,它的核心思想就是使 ...
- groovy常用语法及实战
groovy语言简介 一种基于JVM的敏捷开发语言,作为编程语言可编译成java字节码,也可以作为脚本语言解释执行. 结合了Python.Ruby和Smalltalk的许多强大的特性 支持面向对象编程 ...
- Java Objective-C AOP
Java Use an AOP library or byte-code engineering (BCEL, cglib, asm, etc) to create a sub-class on th ...
- 【leetcode-49】字母异位词分组
给定一个字符串数组,将字母异位词组合在一起.字母异位词指字母相同,但排列不同的字符串. 示例: 输入: ["eat", "tea", "tan&quo ...
- 集成开发环境(IDE)
学习目标: 1.了解Java的IDE开发工具 2.会使用Eclipse.IDEA开发工具新建项目,编写代码,并运行程序. 学习过程: 使用文本开发效率无疑是很低的,每次编写完代码后,还需要手动的编译执 ...
- K8S学习笔记之使用Fluent-bit将容器标准输入和输出的日志发送到Kafka
0x00 概述 K8S内部署微服务后,对应的日志方案是不落地方案,即微服务的日志不挂在到本地数据卷,所有的微服务日志都采用标准输入和输出的方式(stdin/stdout/stderr)存放到管道内,容 ...
- TServerSocket组件
主要作为服务器端的套接字管理器使用.它封装了服务器端的套接字.在打开套接字后,服务器端就处于监听状态,在接收到其它机器的连接请求后,与客户端建立连接,创建一个新的套接字,用于和客户端互传数据,此时TS ...
- ubuntu开发常用收集
命令: 1.http://blog.csdn.net/simongeek/article/details/45271089 2.http://www.jianshu.com/p/654be9c0f13 ...
- jQuery中cookie的简单操作
jQuery 可以通过 jquery.cookie.js 插件来操作 Cookie. 用NuGet安装:PM>Install-Package js-cookie -Version 官网:http ...