/***********************************************************     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 T>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<class T>Stack<T>::Stack(int the_size): its_size(the_size), top(-1), items(0){	its_array = new T[the_size];}template<class T>Stack<T>::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<rhs.items; i++)		its_array[i] = rhs.its_array[i];}template<class T>Stack<T>::~Stack(){	delete[] its_array;}template<class T>Stack<T> &Stack<T>::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<rhs.items; i++)		its_array[i] = rhs.its_array[i];}				template<class T>void Stack<T>::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<items; i++)	     	temp_array[i] = its_array[i];	     		     delete[] its_array;	     its_size *= 2;	     its_array = new T[its_size];	     	     for(int i=0; i<items; i++)	     	its_array[i] = temp_array[i];	     		     delete[] temp_array;	    }}template<class T>T Stack<T>::Pop(){		return its_array[top--];}template<class T>T Stack<T>::Top(){	return its_array[top];}template<class T>bool Stack<T>::IsEmpty(){	return (top == -1);}				#endif
