#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
#include <list>
#include <algorithm>
#include <string>

class Hero
{
public:
    Hero(int age, int height, string name)
    {
        this->m_name = name;
        this->m_age = age;
        this->m_height = height;
    }
    int m_age;
    int m_height;
    string m_name;
    /* overloading operator == */
    bool operator==(const Hero &h) const
    {
        return m_age == h.m_age && m_name == h.m_name && m_height == h.m_height;
    }
};

void printList(list<Hero> &L)
{
    for (list<Hero>::iterator it = L.begin(); it != L.end(); it++)
    {
        cout << "姓名：" << (*it).m_name << "|年齡：" << (it)->m_age << "|身高：" << (it)->m_height << endl;
    }
}

bool listCompare(Hero &h1, Hero &h2)
{
    if (h1.m_age == h2.m_age)
    {
        return h1.m_height > h2.m_height;
    }

    return h1.m_age < h2.m_age;
}

void test01()
{
    list<Hero> L;
    Hero h1(24, 165, "關羽");
    Hero h2(35, 175, "劉備");
    Hero h3(29, 188, "張飛");
    Hero h4(46, 167, "趙雲");
    Hero h5(17, 182, "孔明");

    L.push_back(h1);
    L.push_back(h2);
    L.push_back(h3);
    L.push_back(h4);
    L.push_back(h5);

    printList(L);

    printf("---------------\n");

    L.sort(listCompare);

    printList(L);

    printf("---------------\n");

    L.remove(h4);
}

int main(int argc, char const *argv[])
{
    system("clear");
    test01();
    return 0;
}
