#include #include "String.h" #include "DList.h" main () { #ifdef CPLUS_BUG19 IvlDList l; #else IvlDListOf l; #endif char c; char s[80]; while ((c = getchar ()) != EOF) { switch (c) { case 'a': scanf (" %s", s); l.Append (NewString (s)); break; case 'p': scanf (" %s", s); l.Prepend (NewString (s)); break; case '+': l.RemoveFirst (); break; case '-': l.RemoveLast (); break; case '\n': continue; case 'r': { IvlDListIterOf li (l); li.GotoEnd (); while (--li) { char* pt = *li; printf ("%s ", pt); } printf ("\n"); continue; } case 'i': { int i; scanf (" %d %s", &i, s); IvlDListIterOf lj (l); while ((i-- > 0) && ++lj) ; l.InsertBefore (lj, NewString (s)); break; } case 'j': { int i; scanf (" %d %s", &i, s); IvlDListIterOf lj (l); while ((i-- > 0) && ++lj) ; l.InsertAfter (lj, NewString (s)); break; } } #ifdef CPLUS_BUG19 IvlDListIter li (l); while (++li) printf ("%s ", (char*) *li); #else IvlDListIterOf li (l); while (++li) { char* pt = *li; printf ("%s ", pt); } #endif printf ("\n"); } }