
#include<iostream>
#include<string>
using namespace std;

template<class T>
struct Link {
    T value;
    Link<T>* prev;
    Link<T>* succ;
    Link<T>(const T& v, Link<T>* p = 0, Link* s = 0)
        : value(v), prev(p), succ(s) { }
    Link<T>* erase() ; /// remove this object from list
    Link<T>* find(const T& s);    // find s in list
    Link<T>* add(Link<T>* p, Link<T>* n);
    Link<T>* add_ordered(Link<T>* p, Link<T>* n);
    Link<T>* move(Link<T>* from, Link<T>* to, const T& d)
    {
        Link<T>* temp = find(d); ///from,d);
        erase(); ///temp);
        return add_ordered(to,temp);
    }
    Link<T>* next() const { return succ; }
    Link<T>* previous() const { return prev; }
};

///---------------------------------------------------------------------------

template<typename T>
Link<T>* insert(Link<T>* p, Link<T>* n);

///---------------------------------------------------------------------------

template<typename T>
void print_all(Link<T>* p);

///---------------------------------------------------------------------------
///from https://github.com/bewuethr/stroustrup_ppp/blob/master/chapter19/chapter19_ex04.cpp
struct God {
    God(const string& n, const string& m, const string& v, const string& w)
        : name(n), mythology(m), vehicle(v), weapon(w) { }
    string name;
    string mythology;
    string vehicle;
    string weapon;
    bool operator==(God g) {
        return g.name == this->name;
    }
    bool operator>(God g) {
        return this->name > g.name ;
    }
};
