llt.cpp


      #include <iostream>
      #include <string>
      
      template <typename T>
        class LinkedList
        { protected:
      
            struct Link
            { T data;
              Link * next; };
      
            Link * first, * current;
      
          public:
      
            LinkedList<T>(void)
            { first=NULL; }
      
            void Add(T item)
            { Link * x = new Link;
              x->next = first;
              first = x;
              x->data=item; }
      
            void StartScan(void)
            { current=first; }
      
            bool MoreToCome(void)
            { return current!=NULL; }
      
            T GetNext(void)
            { T answer = current->data;
              current = current->next;
              return answer; } };
      
      
      void main(void)
      {
        LinkedList<string> thelist;
      
        while (true)
        { string s;
          cin >> s;
          if (s=="end") break;
          thelist.Add(s); }
      
        cout << "You said:\n";
      
        thelist.StartScan();
        while (thelist.MoreToCome())
        { string x = thelist.GetNext();
          cout << x << "\n"; }
      
        cout << "The end\n"; }