当前位置:网站首页>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;
}
}

如有错误,多多指教
边栏推荐
猜你喜欢
随机推荐
CF338E Optimize!
永州动力电池实验室建设合理布局方案
ccs软件的使用(靠谱挣钱的app软件)
Digital signal processing course lab report (what foundation is needed for digital signal processing)
What should I do if the sql server installation fails (what should I do if the sql server cannot be installed)
时序数据库在船舶风险管理领域的应用
A new generation of open source free terminal tools, so cool
二手手机销量突破3亿部,与降价的iPhone夹击国产手机
LeetCode二叉树系列——144.二叉树的最大深度
redis6.0 源码学习(五)ziplist
OFDM Sixteen Lectures 3- OFDM Waveforms
BI-SQL丨WHILE
LeetCode二叉树系列——199二叉树的右视图
Web消息推送之SSE
Chapter6 : Has Artificial Intelligence Impacted Drug Discovery?
43.【list的简单属性】
LeetCode二叉树系列——144.二叉树的最小深度
No-code development platform application visible permission setting introductory tutorial
The main content of terrain analysis (the special effect level of the wandering earth)
eclipse连接SQL server数据库「建议收藏」









