# include<iostream>
# include<cstdio>
# define SIZE 20
using namespace std;
class stack
{
public:
int a[SIZE];
int tos; // Top of Stack
stack();
void push(int);
int pop();
int isempty();
int isfull();
};
stack::stack()
{
tos=0; //Initialize Top of Stack
}
int stack::isempty()
{
return (tos==0?1:0);
}
int stack::isfull()
{
return (tos==SIZE?1:0);
}
void stack::push(int i)
{
if(isfull()!=1)
{
cout<<"Pushing "<<i<<endl;
a[tos++]=i;
}
else
{
cout<<"Stack overflow error Possible Data Loss !";
}
}
int stack::pop()
{
if(isempty()!=1)
{
cout<<"Popping "<<a[tos-1]<<endl;
return(a[--tos]);
}
else
{
cerr<<"Stack is empty! What to pop...!";
}
return 0;
}
int main()
{
stack s;
s.push(1);
s.push(2);
s.push(3);
s.pop();
s.pop();
return 0;
}
# include<cstdio>
# define SIZE 20
using namespace std;
class stack
{
public:
int a[SIZE];
int tos; // Top of Stack
stack();
void push(int);
int pop();
int isempty();
int isfull();
};
stack::stack()
{
tos=0; //Initialize Top of Stack
}
int stack::isempty()
{
return (tos==0?1:0);
}
int stack::isfull()
{
return (tos==SIZE?1:0);
}
void stack::push(int i)
{
if(isfull()!=1)
{
cout<<"Pushing "<<i<<endl;
a[tos++]=i;
}
else
{
cout<<"Stack overflow error Possible Data Loss !";
}
}
int stack::pop()
{
if(isempty()!=1)
{
cout<<"Popping "<<a[tos-1]<<endl;
return(a[--tos]);
}
else
{
cerr<<"Stack is empty! What to pop...!";
}
return 0;
}
int main()
{
stack s;
s.push(1);
s.push(2);
s.push(3);
s.pop();
s.pop();
return 0;
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন