#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#define size 3
int push();
int pop();
int push()
{
int z;
cout<<"\nEnter the value of z: ";
cin>>z;
return(z);
}
int pop()
{
return(0);
}
void main()
{
int ar[size],top,a,value;
char ch='y';
clrscr();
top=-1;
while(ch=='Y'||ch=='y')
{
cout<<"\n1.push";
cout<<"\n2.pop";
cout<<"\n3.display";
cout<<"\n4.exit";
cout<<"\nEnter your choice :";
cin>>a;
switch(a)
{
case 1:if(top>=size-1)
{
cout<<"\nstack overflow";
}
else
{
top=top+1;
ar[top]=push();
}
break;
case 2:if(top==1)
{
cout<<"\nstack underflow";
}
else
{
value=ar[top];
cout<<"\npopped element :"<<value;
top=top-1;
}
break;
case 3:
for(int i=0;i<=top;i++)
{
cout<<"\nthe stack value are :"<<ar[i];
}
break;
case 4:
exit;
break;
default:
cout<<"\nwrong choice";
}
cout<<"\ndo you want to continue (press y): ";
cin>>ch;
getch();
}
}
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#define size 3
int push();
int pop();
int push()
{
int z;
cout<<"\nEnter the value of z: ";
cin>>z;
return(z);
}
int pop()
{
return(0);
}
void main()
{
int ar[size],top,a,value;
char ch='y';
clrscr();
top=-1;
while(ch=='Y'||ch=='y')
{
cout<<"\n1.push";
cout<<"\n2.pop";
cout<<"\n3.display";
cout<<"\n4.exit";
cout<<"\nEnter your choice :";
cin>>a;
switch(a)
{
case 1:if(top>=size-1)
{
cout<<"\nstack overflow";
}
else
{
top=top+1;
ar[top]=push();
}
break;
case 2:if(top==1)
{
cout<<"\nstack underflow";
}
else
{
value=ar[top];
cout<<"\npopped element :"<<value;
top=top-1;
}
break;
case 3:
for(int i=0;i<=top;i++)
{
cout<<"\nthe stack value are :"<<ar[i];
}
break;
case 4:
exit;
break;
default:
cout<<"\nwrong choice";
}
cout<<"\ndo you want to continue (press y): ";
cin>>ch;
getch();
}
}
0 Comments