
/** G. Hagopian
4. Modify class Link from §17.9.3 to be a template with the type
of value as the template argument. Then redo exercise 13 from
Chapter 17 with Link<God>.

13. Modify the Link class from §17.10.1 to hold a value of a
struct God. struct God should have members of type string: name,
mythology, vehicle, and weapon. For example,
God{"Zeus", "Greek", "", "lightning"} and
God{"Odin", "Norse", "Eight-legged flying horse called Sleipner", "Spear called Gungnir"}.
Write a print_all() function that lists gods with their attributes
one per line. Add a member function add_ordered() that places
its new element in its correct lexicographical position. Using
the Links with the values of type God, make a list of gods from
three mythologies; then move the elements (gods) from
that list to three lexicographically ordered lists —
one for each mythology.
*/

/** template<typename T>
class Link {
public:
    T value;

    Link(const T& v, Link* p = 0, Link* s = 0)
        : value(v), prev(p), succ(s) { }

    Link* insert(Link* n) ;   // insert n before this object
    Link* add(Link* n) ;      // insert n after this object
    Link* erase() ;           // remove this object from list
    Link* find(const T& s);    // find s in list
    const Link* find(const string& s) const; // find s in list

    Link* advance(int n) const;     // move n positions in list

    Link* next() const { return succ; }
    Link* previous() const { return prev; }
private:
    Link* prev;
    Link* succ;
};*/

#include "linkofgod.h"

int main() {
    Link<God>* all_gods = new Link<God>(God("Thor","Norse",
        "Pinzgauer","Hammer"));
    all_gods = insert(all_gods,
                      new Link<God>
                      (God("Odin","Norse","Eight-legged horse","")));
    all_gods = insert(all_gods,new Link<God>(God("Zeus","Greek",
        "","Lightning")));
    all_gods = insert(all_gods,new Link<God>(God("Freia","Norse",
        "F-transport","F-weapon")));
    all_gods = insert(all_gods,new Link<God>(God("Hera","Greek",
        "H-transport","Spear")));
    all_gods = insert(all_gods,new Link<God>(God("Athena","Greek",
        "A-transport","A-weapon")));
    all_gods = insert(all_gods,new Link<God>(God("Mars","Roman",
        "M-transport","M-weapon")));
    all_gods = insert(all_gods,new Link<God>(God("Poseidon","Greek",
        "Seahorse","Trident")));
    all_gods = insert(all_gods,new Link<God>(God("Ares","Greek",
        "A-transport","A-weapon")));
    all_gods = insert(all_gods,new Link<God>(God("Vesuvius","Roman",
        "V-transport","Volcano")));
    all_gods = insert(all_gods,new Link<God>(God("Bacchus","Roman",
        "Stretcher","Wine goblet")));

    cout << "\nAll gods: " << endl;
    print_all(all_gods);

    /** Note that we may have a problem here with
    all_gods calling its move() function which takes all_gods as
    a parameter*/
    Link<God>* norse_gods = nullptr;
    norse_gods = all_gods->move(all_gods,norse_gods,
        God("Odin","Norse","Eight-legged horse",""));
    norse_gods = all_gods->move(all_gods,norse_gods,God("Thor","Norse",
        "Pinzgauer","Hammer"));
    norse_gods = all_gods->move(all_gods,norse_gods,God("Freia","Norse",
        "F-transport","F-weapon"));

    Link<God>* greek_gods = 0;
    greek_gods = all_gods->move(all_gods,greek_gods,God("Hera","Greek",
        "H-transport","Spear"));
    greek_gods = all_gods->move(all_gods,greek_gods,God("Athena","Greek",
        "A-transport","A-weapon"));
    greek_gods = all_gods->move(all_gods,greek_gods,God("Poseidon","Greek",
        "Seahorse","Trident"));
    greek_gods = all_gods->move(all_gods,greek_gods,God("Zeus","Greek",
        "","Lightning"));
    greek_gods = all_gods->move(all_gods,greek_gods,God("Ares","Greek",
        "A-transport","A-weapon"));

    Link<God>* roman_gods = 0;
    roman_gods = all_gods->move(all_gods,roman_gods,God("Mars","Roman",
        "M-transport","M-weapon"));
    roman_gods = all_gods->move(all_gods,roman_gods,God("Vesuvius","Roman",
        "V-transport","Volcano"));
    roman_gods = all_gods->move(all_gods,roman_gods,God("Bacchus","Roman",
        "Stretcher","Wine goblet"));

    /// all_gods is now empty - this should probably be part of the erase
    /// function
    all_gods = 0;

    cout << "\nAll gods:\n";
    cin.get();
    print_all(all_gods);
    cout << "\nNorse gods:\n";
    print_all(norse_gods);
    cout << "\nGreek gods:\n";
    print_all(greek_gods);
    cout << "\nRoman gods:\n";
    print_all(roman_gods);
}
