Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

/users/u3/mtikir/PMaCInstrumentor_v1601/include/Stack.h

Go to the documentation of this file.
00001 #ifndef _Stack_h_
00002 #define _Stack_h_
00003 
00004 template <class T=uint32_t>
00005 class Stack {
00006 private:
00007     uint32_t maxSize;
00008     T* elements;
00009     int32_t topIndex;
00010 public:
00011     Stack(uint32_t size){
00012         maxSize = size;
00013         elements = new T[size];
00014         topIndex = -1;
00015     }
00016     ~Stack(){
00017         delete[] elements;
00018     }
00019 
00020     void clear(){
00021         topIndex = -1;
00022     }
00023 
00024     void push(T elt){
00025         ASSERT((topIndex+1) < maxSize);
00026         elements[++topIndex] = elt;
00027     }
00028     T pop(){
00029         ASSERT(topIndex >= 0);
00030         return elements[topIndex--];
00031     }
00032     bool empty(){ 
00033         return (topIndex == -1);
00034     }
00035     T top(){
00036         return elements[topIndex];
00037     }
00038     void print(){
00039         PRINT_INFOR("topIndex:%d ",topIndex);
00040         PRINT_INFOR("maxSize :%d ",maxSize);
00041         PRINT_INFOR("\n");
00042     }
00043 };
00044 
00045 #endif

Generated on Mon Jan 28 11:08:31 2008 for PMaCInstrumentor by doxygen 1.3.5