#include #include"list.h" #include"stack.h" #include"queue.h" int main() { // declare one of each List list; Stack stack; Queue queue; ListContainer * foo; // a pointer of base class type // this allows us to use a pointer and not // be specific about what it is really pointing to, // since all of the methods are virtual or defined // in the base class, it won't matter which ones I // call offset from the pointer. // list, stack, and queue are all guaranteed // to have Empty, Insert, Name, LongName // and both versions of Delete // list foo = &list; // point it at the list foo->LongName(); foo->Name(); for( int i = 0 ; i < 10 ; i++ ) foo->Insert( 10 - i ); foo->Delete(5); cout << "deleted 5" << endl; while( !foo->Empty() ) cout << foo->Delete() << " "; cout << endl; // stack foo = &stack; // point it at the stack foo->LongName(); foo->Name(); for( int i = 0 ; i < 10 ; i++ ) foo->Insert( 10 - i ); foo->Delete(5); cout << "deleted 5" << endl; // violates stack while( !foo->Empty() ) cout << foo->Delete() << " "; cout << endl; // queue foo = &queue; // point it at the stack foo->LongName(); foo->Name(); for( int i = 0 ; i < 10 ; i++ ) foo->Insert( 10 - i ); foo->Delete(5); // violates queue cout << "deleted 5" << endl; while( !foo->Empty() ) cout << foo->Delete() << " "; cout << endl; return 0; }