//To implement stacks using array//
#include "iostream.h"
#include"conio.h"
#include"ctype.h"
#define SIZE 10
class stack
{
private:
int stck[SIZE];
int top;
public:
stack()
{
top=-1;
}
void push(int);
int pop(void);
int IsEmpty(void);
};
void stack:: push(int term)
{
if(top==SIZE-1)
{
cout<<"OVERFLOW";
getch();
} else stck[++top]=term;
}
int stack::pop(void)
{ return(stck[top--]);
}
int stack::IsEmpty(void)
{ if(top==-1) return(1);
else return(0); }
int main(void)
{ stack s; char choice; int term;
do
{ clrscr();
cout<<"-> MENU <-" <<> Push" <<> Pop" <<> Exit" <<>>choice;
choice=toupper(choice);
clrscr();
switch(choice)
{
case 'P':
cout<<"Enter the term to push:"; cin>>term;
s.push(term);
break;
case 'O':
if(s.IsEmpty())
cout<<"UNDERFLOW";
else cout<<"Popped term is " << s.pop();
getch();
break;
case 'E': cout<<"Exiting";
getch();
break;
default:
cout<<"Not a valid choice";
getch();
break; }
}
while(choice!='E');
return(0);
}
#include "iostream.h"
#include"conio.h"
#include"ctype.h"
#define SIZE 10
class stack
{
private:
int stck[SIZE];
int top;
public:
stack()
{
top=-1;
}
void push(int);
int pop(void);
int IsEmpty(void);
};
void stack:: push(int term)
{
if(top==SIZE-1)
{
cout<<"OVERFLOW";
getch();
} else stck[++top]=term;
}
int stack::pop(void)
{ return(stck[top--]);
}
int stack::IsEmpty(void)
{ if(top==-1) return(1);
else return(0); }
int main(void)
{ stack s; char choice; int term;
do
{ clrscr();
cout<<"-> MENU <-" <<> Push" <<> Pop" <<> Exit" <<>>choice;
choice=toupper(choice);
clrscr();
switch(choice)
{
case 'P':
cout<<"Enter the term to push:"; cin>>term;
s.push(term);
break;
case 'O':
if(s.IsEmpty())
cout<<"UNDERFLOW";
else cout<<"Popped term is " << s.pop();
getch();
break;
case 'E': cout<<"Exiting";
getch();
break;
default:
cout<<"Not a valid choice";
getch();
break; }
}
while(choice!='E');
return(0);
}