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

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

Go to the documentation of this file.
00001 #ifndef __J2K__ArrayBased_Stack_HPP__
00002 #define __J2K__ArrayBased_Stack_HPP__
00003 
00004 #include <j2k/Fred/Basic.hpp>
00005 
00006 #define LIST_SIZE    100
00007 
00008 class ArrayStack {                           // Array-based stack class
00009 public:
00010 
00011   inline ArrayStack()                        // Default Constructor
00012     : size( LIST_SIZE ), top( 0 ) 
00013   {
00014     listarray = new Elem[ LIST_SIZE ];
00015   }
00016 
00017   inline ArrayStack( unsigned long sz )      // Constructor with Size   
00018     : size( LIST_SIZE ), top( 0 ) 
00019   {
00020     listarray = new Elem[sz];
00021   }
00022 
00023   inline virtual ~ArrayStack()               // Destructor: delete the array
00024   {
00025     delete [] listarray;
00026   }
00027 
00028   inline void clear()                        // Remove all Elem's from stack
00029   {
00030     top = 0;
00031     memset( listarray, 0, ( sizeof( Elem ) * LIST_SIZE ) );
00032   }
00033 
00034   inline void push( const Elem item )        // Push Elem onto stack
00035   {
00036     assert(top < size);
00037     listarray[top] = item;
00038     top++;
00039   }
00040 
00041   inline Elem pop()                          // Pop Elem from top of stack
00042   {
00043     assert( !isEmpty() );
00044     --top;
00045     return listarray[ top ];
00046   }
00047 
00048   inline Elem topValue() const               // Return value of top Elem
00049   {
00050     assert( !isEmpty() );
00051     return listarray[ top-1 ];
00052   }
00053 
00054   inline BOOL isEmpty() const                // Return TRUE if stack is empty
00055   {
00056     return (top == 0);
00057   }
00058 
00059   inline BOOL isFilled() const               // Return TRUE if NOT empty
00060   {
00061     return (top != 0);
00062   }
00063 
00064 private:
00065   unsigned long size;                        // Maximum size of stack
00066   unsigned long top;                         // Index for top Elem
00067   Elem *listarray;                           // Array holding stack Elem's
00068 };
00069 
00070 #endif // End of ArrayStack.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