当前位置:网站首页>Container sorting case
Container sorting case
2022-07-30 14:30:00 【old fish 37】

#include<iostream>
using namespace std;
#include<list>
#include<string>
//创建模板
class Person
{
public:
Person(string name, int age, int high)
{
m_name = name;
m_age = age;
m_high = high;
}
public:
string m_name;
int m_age;
int m_high;
};
bool Compare(Person& p1, Person& p2)
{
if (p1.m_age == p2.m_age)
{
return p1.m_high>p2.m_high;
}
else
{
return p1.m_age > p2.m_age;
}
}
int main()
{
Person p1("刘备", 20, 150);
Person p2("关羽", 20, 170);
Person p3("张飞", 20, 190);
//创建容器 save class
list<Person>v;
v.push_back(p1);
v.push_back(p2);
v.push_back(p3);
//比较函数 重新构造
v.sort(Compare);
for (list<Person>::iterator it = v.begin(); it != v.end(); it++)
{
cout << "名字:" << it->m_name << " " << "年龄:" << it->m_age << " "
<< "身高为:" << it->m_high << endl;
}
}

如有错误,多多指教
边栏推荐
猜你喜欢
随机推荐
简单理解精确率(Precision),召回率(Recall),准确率(Accuracy),TP,TN,FP,FN
关于华为应用市场审核App无法启动的问题
CF603E Pastoral Oddities
No-code development platform all application settings introductory tutorial
Conversion between pytorch and keras (the code takes LeNet-5 as an example)
No-code development platform application visible permission setting introductory tutorial
Redis6.0 source code learning (5) ziplist
[ARC092D] Two Faced Edges
【Pytorch】如何在关闭batch-norm的同时保持Dropout的开启
Eclipse connects to SQL server database "recommended collection"
开源工具推荐:高性能计算辅助工具MegPeak
BI-SQL丨WHILE
[论文翻译] Unpaired Image-To-Image Translation Using Cycle-Consistent Adversarial Networks
八年测试经验,为何惨遭领导痛批:你写的测试文档还不如刚来的应届生
吃透Chisel语言.28.Chisel进阶之有限状态机(二)——Mealy状态机及与Moore状态机的对比
NFTScan 与 PANews 联合发布多链 NFT 数据分析报告
(HR面试)最常见的面试问题和技巧性答复
ECCV 2022 | 通往数据高效的Transformer目标检测器
LeetCode二叉树系列——199二叉树的右视图
网站添加能换装可互动的live 2d看板娘








