#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include <deque>
#include<list>
using namespace std;
class person
{
public:
person(string name,int age, int tall)
{
this->name = name;
this->age = age;
this->tall = tall;
}
string name;
int age;
int tall;
};
void test01(list<person>& l)
{
for (list<person>::iterator it = l.begin(); it != l.end(); it++)
{
cout << (*it).name << " " << it->age << " " << it->tall << " " << endl;
}
cout << endl;
}
bool compare(person& p1,person&p2)
{
if (p1.age==p2.age)
{
return p1.tall > p2.tall;
}
else
{
return p1.age < p2.age;
}
}
void test()
{
person p1("李四", 20, 198);
person p2("的撒", 60, 200);
person p3("木子", 25, 160);
person p4("木木", 25, 162);
person p5("阿飞", 25, 163);
person p6("小新", 50, 175);
list<person>l1;
l1.push_back(p1);
l1.push_back(p2);
l1.push_back(p3);
l1.push_back(p4);
l1.push_back(p5);
l1.push_back(p6);
test01(l1);
l1.sort(compare);
test01(l1);
}
int main() {
test();
system("pause");
return 0;
}