// Stack.h // defines the Array implementation of // the Stack class described // in the CS341 lecture notes // Spring 1998 #ifndef STACK_H #define STACK_H #include const int Default_Size = 10; template class Stack { private: unsigned int Full_Stack; // really size int Top_Of_Stack; // index to last used slot Element_Type *Stack_Array; // pointer to the data public: // default constructor with default size Stack ( unsigned int Max_Size = Default_Size); // copy constructor Stack (const Stack& Value); // destructor -- deallocate memory ~Stack () { delete [] Stack_Array; cout << "destroyed a stack of size " << Full_Stack << endl; } // assignment operator const Stack& operator= (const Stack& Value); // add a new data element to the top of the stack void Push ( const Element_Type& X); // remove the top element of the stack void Pop (); // retrieve the top element of the stack // but don't remove it const Element_Type& Top() const; // remove and return the top element of the stack Element_Type Pop_And_Top (); // clear out the stack void Make_Empty () { Top_Of_Stack = -1; } // returns 1 if stack is empty; 0 if not empty int isEmpty() const { return Top_Of_Stack == -1; } // returns 1 if stack is full; 0 if not full int isFull () const { return Top_Of_Stack == Full_Stack - 1; } // print the contents of the stack friend ostream& operator<<(ostream& out, const Stack& s) { out << "Contents of the Stack:" << endl; for (int i = 0; i <= s.Top_Of_Stack; i++) { out << "[" << i << "] " << s.Stack_Array[i] << endl; } return out; } }; #endif