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

Stack Class Reference

#include <Stack.hpp>

List of all members.

Public Methods

 Stack ()
 Stack (DBase *item)
 Stack (const Stack &stk)
void push (DBase *item)
DBasepop ()
DBasetopValue () const
void clear ()
void display () const
virtual ~Stack ()
int getSize () const
bool isEmpty () const
bool isNotEmpty () const

Private Attributes

Linktop
int size


Constructor & Destructor Documentation

Stack::Stack  
 

Definition at line 4 of file Stack.cpp.

00004              {                        // Default Constructor
00005    top  = NULL;
00006    size = 0;
00007 }

Stack::Stack DBase   item
 

Definition at line 9 of file Stack.cpp.

00009                           {           // First item Constructor
00010     top  = new Link( item, NULL );
00011     size = 1;
00012 }

Stack::Stack const Stack &    stk
 

Definition at line 14 of file Stack.cpp.

00014                                {      // Copy Constructor
00015     Link* fromCurr = stk.top;
00016     Link* toCurr   = new Link( *fromCurr );
00017 
00018    top = toCurr;                       // Setting the top pointer
00019     size = 1;
00020 
00021     while ( fromCurr->next != NULL ) {  // Is it the end of the from Stack ?
00022 
00023         fromCurr = fromCurr->next;      // Move forward in the reading stack
00024 
00025         toCurr->next = new Link( *fromCurr ); // Copy the next Link content
00026 
00027         toCurr = toCurr->next;          // Move forward in the writing stack
00028         size++;                         // We just added a new Link
00029     }
00030 
00031     if ( size != stk.size ) {
00032         cout << "An error occured while copying the Stack to a new Stack\n";
00033     }
00034 }

virtual Stack::~Stack   [inline, virtual]
 

Definition at line 32 of file Stack.hpp.

00032                  {                  // Destructor
00033    clear();
00034 }


Member Function Documentation

void Stack::clear  
 

Definition at line 56 of file Stack.cpp.

Referenced by ~Stack().

00056                   {               // Clear the stack
00057       if ( isEmpty() )           // If it's empty then get out.
00058       return;
00059 
00060    while( top != NULL ) {
00061         Link* temp = top;
00062         top = top->next;
00063         delete temp;
00064         size--;
00065     }
00066 
00067     assert( top == NULL );
00068 }

void Stack::display   const
 

Definition at line 75 of file Stack.cpp.

00075                           {
00076     Link* curr = top;
00077 
00078    if ( isEmpty() )           // If it's empty then get out.
00079       return;
00080 
00081    while ( curr->next != NULL ) {  // Is it the end of the from Stack ?
00082 
00083       curr->element->display();
00084         curr = curr->next;       // Move forward in the reading stack
00085     }
00086 
00087 }

int Stack::getSize   const [inline]
 

Definition at line 36 of file Stack.hpp.

00036                            {
00037     return size;
00038 }

bool Stack::isEmpty   const [inline]
 

Definition at line 40 of file Stack.hpp.

Referenced by clear(), display(), pop(), and topValue().

00040                             {       // The Stack is empty ?
00041     return ( top == NULL ) || ( size < 1 );
00042 }

bool Stack::isNotEmpty   const [inline]
 

Definition at line 44 of file Stack.hpp.

Referenced by Parenth::read().

00044                                {    // The Stack is not empty ?
00045     return ( top != NULL ) && ( size > 0 );
00046 }

Elem Stack::pop  
 

Definition at line 41 of file Stack.cpp.

Referenced by Parenth::read().

00041                   {               // Remove an item from the top
00042 
00043    if ( isEmpty() )
00044       return NULL;
00045 
00046     DBase* dtemp = top->element;
00047     Link* ltemp = top->next;
00048 
00049     delete top;
00050     top = ltemp;
00051     size--;
00052 
00053     return dtemp;
00054 }

void Stack::push DBase   item
 

Definition at line 36 of file Stack.cpp.

Referenced by Parenth::read().

00036                               {  // Insert an item at the top
00037     top = new Link( item, top );
00038     size++;
00039 }

DBase & Stack::topValue   const
 

Definition at line 70 of file Stack.cpp.

00070                              {    // What's the top Value ?
00071     assert( !isEmpty() );
00072     return *top->element;
00073 }


Member Data Documentation

int Stack::size [private]
 

Definition at line 51 of file Stack.hpp.

Referenced by Stack().

Link* Stack::top [private]
 

Definition at line 50 of file Stack.hpp.

Referenced by Stack().


The documentation for this class was generated from the following files:
Generated on Sun Oct 14 18:49:50 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001