Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

#include <iostream>

using namespace std;


#define MAX_ITEMS 20;

class StackType
{
public:
StackType();
~StackType();
bool IsEmpty() const;
bool IsFull() const;
void Push(ItemType newItem);
void Pop();
void MakeEmpty();
ItemType Top() const;
private:
int top;
ItemType items[MAX_ITEMS];
};

StackType::StackType()
{
top = -1; }
StackType::~StackType(){

StackType::MakeEmpty(){
top=-1;
}
bool StackType::IsEmpty() const
{
return (top == -1);
}
bool StackType::IsFull() const
{
return (top == MAX_ITEMS-1);
}
void StackType::Push(ItemType newItem)
{
if (IsFull())
throw FullStack();
top++;
items[top] = newItem;
}
void StackType::Pop()
{
if(IsEmpty())
throw EmptyStack();
top--; }
ItemType StackType::Top() const
{
if (IsEmpty())
throw EmptyStack();
return items[top];
}

void main(){
StackType S;
int i;
ItemType myItem;
cin>>myItem;
S::StackType();
for(i=0;i<20;i++){
S.Push(myItem);
}
if(IsFull())
S.Pop();
if(IsEmpty())
S.MakeEmpty();
S.~StackType();
}

You might also like