#include #include "String.h" #include "Chain.h" class C { public: C* Next; char* IvlString; inline C (const char* c) : Next (0), IvlString (NewString (c)) {} inline C* GetNext () const { /*printf ("GetNext (%x) = %x)\n", this, Next); */ return Next; } inline void SetNext (C* c) { /*printf ("SetNext (%x, %x)\n", this, c); */ Next = c; } }; main () { IvlChainOf l; char c; char s[80]; while ((c = getchar ()) != EOF) { switch (c) { case 'a': scanf (" %s", s); l.Append (new C (s)); break; case 'p': scanf (" %s", s); l.Prepend (new C (s)); break; case '+': l.RemoveFirst (); break; case '-': l.RemoveLast (); break; case '\n': continue; case 'i': { int i; scanf (" %d %s", &i, s); IvlChainIterOf lj (l); while ((i-- > 0) && ++lj) ; l.InsertBefore (lj, new C (s)); break; } case 'j': { int i; scanf (" %d %s", &i, s); IvlChainIterOf lj (l); while ((i-- > 0) && ++lj) ; l.InsertAfter (lj, new C (s)); break; } } IvlChainIterOf li (l); while (++li) { C* pt = *li; printf ("%s ", pt->IvlString); } printf ("\n"); } }