Stacks Programs Sorry about the photos It wouldnt let me rot
Stacks Programs
Sorry about the photos. It wouldnt let me rotate them for some reason
Here are the directions for each program
Solution
/*****ArrayStackAdt*************************/
#include <iostream>
using namespace std;
template<class T>
class ArrayStackDataStructure
{
public:
ArrayStackDataStructure();
~ArrayStackDataStructure(){delete[] S;}//destructor
ArrayStackDataStructure(int MaxStackSize);//overloaded construct
ArrayStackDataStructure(const ArrayStackDataStructure& rhs);//copy construct
int intializeStack()const{return top=-1;}
int IsEmptyStack()const{return top==-1;}
int IsFullStack()const{return top==MaxTop;}
T Peek()const;
void Push(T);
T Pop();
private:
int top; //current top of stack
int MaxTop; //max val for top
T *S; //element array
};
template<class T>
ArrayStackDataStructure<T>::ArrayStackDataStructure(int MaxStackSize)
{
MaxTop=MaxStackSize-1;
S=new T[MaxStackSize];
top=-1;
}
template<class T>
ArrayStackDataStructure<T>::ArrayStackDataStructure(const ArrayStackDataStructure& rhs)
{
MaxTop=rhs.MaxTop;
S=rhs.S;
top=rhs.top;
}
template<class T>
void ArrayStackDataStructure<T>::Push(T x)
{
if(IsFullStack())
throw \"ArrayStackDataStructure<>::IsFullStack(): full stack\";
else
S[++top]=x;
}
template<class T>
T ArrayStackDataStructure<T>::Pop()
{
if(IsEmptyStack())
throw \"ArrayStackDataStructure<>::IsEmptyStack(): full stack\";
else
return S[top--];
}
template<class T>
T ArrayStackDataStructure<T>::Peek()const
{
if(IsEmptyStack())
throw \"ArrayStackDataStructure<>::IsEmptyStack(): full stack\";
else
return S[top];
}
int main() {
// your code goes here
try
{
ArrayStackDataStructure<int>PrimeFactoriztionDemoClass(50);
//insert into stack
PrimeFactoriztionDemoClass.Push(7);
cout <<PrimeFactoriztionDemoClass.Peek() <<endl;
// Add your test operations here
}
catch (exception const& ex) {
cerr << \"Exception: \" << ex.what() <<endl;
return -1;
}
return 0;
}

