[ create a new paste ] login | about

Link: http://codepad.org/CP23icTR    [ raw code | output | fork ]

C++, pasted on Oct 17:
#include<iostream.h>
#include<iomanip.h>
#include<stdlib.h>
#define SIZE 10
class stack1
{
public:
int stck[SIZE];
int top;
void init()
{
top=0;
}
void push(int op)
{
try
{
if(top==10)
throw top;
}
catch(int)
{
cout<<"Stack is Full \n";
return;
}
++top;
stck[top]=op;
}
int pop()
{
try
{
if(top==0)
throw 0;
}
catch(int)
{
cout<<"Stack is Empty!\n";
return 0;
}
top--;
return stck[top];
}
};
int main()
{
stack1 s1;
stack1 s2;
int i;
s1.init();
//s2.init();
s1.push(12);
s1.push(23);
s1.push(34);
/*s2.push(45);
s2.push(56);
s2.push(67);*/

for(i=0;i<3;i++)
cout<<"Pop Stack 1:"<<s1.pop()<<endl;
//for(i=0;i<4;i++)
//cout<<"\n Pop Stack 2:"<<s2.pop()<<endl;
return 0;
}


Output:
1
2
3
Pop Stack 1:23
Pop Stack 1:12
Pop Stack 1:-1079333560


Create a new paste based on this one


Comments: