00001 #ifndef __J2K__Linked_Stack_HPP__
00002 #define __J2K__Linked_Stack_HPP__
00003
00004 #include <j2k/Fred/Basic.hpp>
00005
00006 class LinkedStack {
00007 public:
00008
00009 inline LinkedStack() : top( NULL ) { }
00010
00011 inline virtual ~LinkedStack() {
00012 clear();
00013 }
00014
00015 void clear();
00016
00017 inline void push( const Elem item )
00018 {
00019 top = new SLink( item, top );
00020 }
00021
00022 Elem pop();
00023
00024 inline Elem topValue() const
00025 {
00026 assert( !isEmpty() );
00027 return top->element;
00028 }
00029
00030 inline BOOL isEmpty() const
00031 {
00032 return (top == NULL);
00033 }
00034
00035 inline BOOL isFilled() const
00036 {
00037 return (top != NULL);
00038 }
00039
00040 private:
00041 SLink *top;
00042
00043 };
00044
00045 void Stack::clear()
00046 {
00047 while( top != NULL )
00048 {
00049 SLink* temp = top;
00050 top = top->next;
00051 delete[] temp;
00052 }
00053
00054 assert( top == NULL );
00055 }
00056
00057 Elem Stack::pop()
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