using namespace std;
int handler=0;
template <class T> class stack
{
public:
T st[20];
int max_length;
int top;
stack(int len)
{
max_length=len;
top=-1;
}
void push(T item) throw(char)
{
if(top==(max_length-1))
{
handler=1;
throw(1);
}
top++;
st[top]=item;
}
T pop() throw(int)
{
if(top<0)
{
handler=2;
throw(1);
return 0;
}
T item;
item=st[top];
top--;
return item;
}
void show_stack()
{
cout<<endl;
for(int i=0;i<=top;i++)
{
cout<<st[i]<<"\t";
}
}
};
void myfunc()
{
if(handler==1)
cout<<"stack overflow\n";
else
cout<<"stack underflow\n";
}
void myfunc1()
{
cout<<"inside unexpected\n";
}
int main()
{
stack <char *>st(5);
set_unexpected(myfunc1);
set_terminate(myfunc);
st.push("ankit");
st.push("rahul");
st.push("ajay");
st.push("amit");
st.push("aniket");
st.push("ritik");
st.show_stack();
return 0;
}
Comments