/*********************************************************** Copyright 2003 Rick Miller - Pulp Free Press This source code accompanies the text C++ For Artists and is provided for instructional purposes only. No warranty concerning the quality of the code is expressed or implied. You are free to use this code in your programs so long as this copyright notice is included in its entirety. **********************************************************/ #ifndef STACK_H #define STACK_H #include "node.h" template class Stack{ public: Stack(int the_size = 50); Stack(const Stack &); ~Stack(); Stack &operator=(const Stack &); void Push(T item); T Pop(); T Top(); bool IsEmpty(); private: T *its_array; int its_size; int items; int top; }; template Stack::Stack(int the_size): its_size(the_size), top(-1), items(0) { its_array = new T[the_size]; } template Stack::Stack(const Stack &rhs):its_size(rhs.its_size), top(rhs.top) , items(rhs.items) { its_array = new T[rhs.its_size]; for(int i=0; i Stack::~Stack(){ delete[] its_array; } template Stack &Stack::operator=(const Stack &rhs){ delete [] its_array; top = rhs.top; items = rhs.items; its_array = new T[rhs.its_size]; for(int i=0; i void Stack::Push(T item){ if(top <= (its_size -2)) its_array[++top] = item; else{ T *temp_array = new T[its_size]; for(int i=0; i T Stack::Pop(){ return its_array[top--]; } template T Stack::Top(){ return its_array[top]; } template bool Stack::IsEmpty(){ return (top == -1); } #endif