You are on page 1of 4

clude<iostream>

using namespace std;

const int MAX_SIZE=100;

class stackoverflow

public:

stackoverflow()

cout<<"stack over flow"<<endl;

};

class stackunderflow

public:

stackunderflow()

cout<<"stack under flow"<<endl;

};

class ArrayStack

private:

int data[MAX_SIZE];

int top;

public:

ArrayStack()

top=-1;

void push(int element)

{
if(top>=MAX_SIZE)

throw new stackoverflow();

data[++top]=element;

int pop()

if(top==-1)

throw new stackunderflow();

return data[top--];

int Top()

return data[top];

int size()

return top+1;

bool isEmpty()

return(top==-1)?true:false;

};

int main()

ArrayStack s;
try{

if(s.isEmpty())

cout<<"stack is empty"<<endl;

s.push(100);

s.push(200);

cout<<"stack of stack:"<<s.size()<<endl;

cout<<s.Top()<<endl;

cout<<s.pop()<<endl;

cout<<s.pop()<<endl;

catch(...)

cout<<"some exception"<<endl;

return 0;

You might also like