Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

/magnus/back_end/general/include/Stack.h

Go to the documentation of this file.
00001 /*
00002  *   $Id: Stack.h,v 1.1.1.1 1995/11/20 17:54:42 rogern Exp $
00003  */
00004 
00005 // Copyright (C) 1994 The New York Group Theory Cooperative
00006 // See magnus/doc/COPYRIGHT for the full notice.
00007 
00008 // Contents: Definition and implementation of classes: Stack<T>.
00009 //
00010 // Principal Author: Sergey Lyutikov
00011 //
00012 // Status: Useable.
00013 //
00014 // Revision History:
00015 //
00016 // Special Notes:
00017 //
00018 // * To instantiate StackOf<T>, class T must have an assignment
00019 //   operator, a copy constructor, an == operator, and destructor.
00020 //
00021 // * Alternative implementation of StackOf class, uses ListRep as
00022 //   the DataRep.
00023 //
00024 
00025 #ifndef _STACK_H_
00026 #define _STACK_H_
00027 
00028 #include "RefCounter.h"
00029 #include "ObjectOf.h"
00030 #include "List.h"
00031 #include "Cell.h"
00032 
00033 
00034 template < class T > class StackOf : public ObjectOf< ListRep<T> > {
00035 
00036 public:
00037 
00038   // Constructors:
00039 
00040   StackOf( ) : ObjectOf< ListRep<T> >( new ListRep<T>() ) { }
00041   // Default constructor makes empty stack.
00042 
00043   StackOf( const T& t ) : ObjectOf< ListRep<T> >( new ListRep<T>(t) ) { }
00044   // Cast constructor T -> StackOf<T>
00045 
00046   // copy constructor, operator=, and destructor supplied by compiler.
00047 
00048   void push( const T& t ) { change()->insert( t, 0 ); }
00049 
00050   T pop( ) { 
00051     T res = look()->element( 0 ); 
00052     change()->removeElementOfIndex( 0 ); 
00053     return res;
00054   }
00055 
00056   void popAll( ) { 
00057     while ( look()->length() ) change()->removeElementOfIndex( 0 ); 
00058   }
00059 
00060   Bool isEmpty( ) const { return !look()->length(); }
00061 
00062   Bool isntEmpty( ) const { return look()->length(); }
00063 
00064 };
00065 
00066 #endif  // _STACK_H_

Generated at Tue Jun 19 09:49:35 2001 for Magnus Classes by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001