Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/DataType/Stack/LinkedStack.hpp

Go to the documentation of this file.
00001 #ifndef __J2K__Linked_Stack_HPP__
00002 #define __J2K__Linked_Stack_HPP__
00003 
00004 #include <j2k/Fred/Basic.hpp>
00005 
00006 class LinkedStack {                        // Linked stack class
00007 public:
00008 
00009   inline LinkedStack() : top( NULL ) { }   // Default Constructor
00010 
00011   inline virtual ~LinkedStack() {          // Destructor: return Elems
00012     clear();
00013   }
00014 
00015   void clear();                            // Remove all Elems from stack
00016 
00017   inline void push( const Elem item )      // Push Elem onto stack
00018   {
00019     top = new SLink( item, top );
00020   }
00021 
00022   Elem pop();                              // Pop Elem from top of stack
00023 
00024   inline Elem topValue() const             // Get value of top Elem
00025   {
00026     assert( !isEmpty() );
00027     return top->element;
00028   }
00029 
00030   inline BOOL isEmpty() const              // Return TRUE if stack is empty
00031   { 
00032     return (top == NULL);
00033   }
00034 
00035   inline BOOL isFilled() const             // Return TRUE if NOT empty
00036   {
00037     return (top != NULL);
00038   }
00039 
00040 private:
00041   SLink *top;                              // Pointer to top stack Elem
00042 
00043 };
00044 
00045 void Stack::clear()                        // Remove all Elems from the stack
00046 {
00047   while( top != NULL )                     // Return link nodes to the freelist
00048   {
00049     SLink* temp = top;
00050     top = top->next;
00051     delete[] temp;
00052   }
00053 
00054   assert( top == NULL );
00055 }
00056 
00057 Elem Stack::pop()                          // Pop Elem from top of stack
00058 {
00059   assert( !isEmpty() );
00060   Elem temp = top->element;
00061   SLink* ltemp = top->next;
00062   delete top;
00063   top = ltemp;
00064   return temp;
00065 }
00066 
00067 #endif // End of LinkedStack.hpp

Generated on Sun Oct 14 18:46:18 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001