#include #include #include using namespace std; class Link { public: string data; Link * next; Link(string d, Link * n = NULL) { data = d; next = n; } }; class List { protected: Link * first; public: List() { first = NULL; } void add_to_front(string x) { first = new Link(x, first); } bool is_present(string x) { Link * ptr = first; while (ptr != NULL) { if (ptr->data == x) return true; ptr = ptr->next; } return false; } void print_all() { Link * ptr = first; while (ptr != NULL) { cout << ptr->data << " "; ptr = ptr->next; } cout << "\n"; } bool remove(string x) { Link * ptr = first, * prev = NULL; while (ptr != NULL) { if (ptr->data == x) { if (prev == NULL) first = ptr->next; else prev->next = ptr->next; delete ptr; return true; } prev = ptr; ptr = ptr->next; } return false; } void reverse() { Link * r = NULL; while (first != NULL) { Link * L = first; Link * n = first->next; L->next = r; first = n; r = L; } first = r; } string remove_first() { assert(first != NULL); string r = first->data; Link * n = first->next; delete first; first = n; return r; } bool empty() { return first == NULL; } ~List() { Link * ptr = first; while (ptr != NULL) { Link * n = ptr->next; delete ptr; ptr = n; } } }; int main() { List L; string s; while (true) { cin >> s; if (s == "end") break; L.add_to_front(s); } L.print_all(); List M; while (! L.empty()) M.add_to_front(L.remove_first()); M.print_all(); }