#include<iostream>
#include<conio.h>
#define MAX 3
using namespace std;
int a[MAX], top = -1;
void push();
void pop();
void peep();
void change();
void size();
int main()
{
int n;
while(1) {
cout<<"\n1. PUSH";
cout<<"\n2. POP";
cout<<"\n3. PEEP";
cout<<"\n4. CHANGE";
cout<<"\n5. is_empty";
cout<<"\n6. size";
cout<<"\nEnter Choice : ";
cin>>n;
switch(n)
{
case 1:
{
push();
break;
}
case 2:
{
pop();
break;
}
case 3:
{
peep();
break;
}
case 4:
{
change();
break;
}
case 5:
{
size();
break;
}
case 6:
{
exit(0);
}
default:
cout<<"\ninvalid choice !!!";
}
getch();
}
}
void push(){
int data;
if(top==MAX-1)
{
cout<<"\noverflow or stack is full !!!";
}
else
{
cout<<"\nEnter the element : ";
cin>>data;
top++;
a[top]=data;
}
}
void pop()
{
if(top==-1)
{
cout<<"\nunder flow STACK or STACK is empty";
}
else
{
cout<<"\nPOP or DELETE element : ",a[top];
top--;
}
}
void size()
{
int i;
if(top>=0)
{
cout<<"\nElemets : ";
for(i=top; i>=0; i--)
{
cout<<"\n",a[i];
}
}
else
{
cout<<"\nThe STACK is Empty";
}
}
void peep()
{
int m;
cout<<"\nEnter the position : ";
cin>>m;
if(top-m<=-1)
{
cout<<"\nSTACK is overflow !";
}
else
{
cout<<"\nThe Elements is : %d",a[top-m];
}
}
void change()
{
int x,y;
cout<<"\nEnter Position for change : ";
cin>>x;
cout<<"\nEnter the Number for change : ";
cin>>y;
if(top-x<=-1)
{
cout<<"\nSTACK is overflow !!!";
}
else
{
a[top-x]=y;
cout<<"\nCHANGE successfull !!!";
}
}
Comments
Leave a comment