/*write a menu driven program using c for static implementation of stack the menu inclide:-
1:-pop
2:-push
3:-display
*/
#include<stdio.h>
#include<conio.h>
int s[30],top=-1;
void push();
void pop();
void display();
void main()
{
int choice;
clrscr();
do
{
printf("\n1:push\n");
printf("\n2:pop\n");
printf("\n3:display\n");
printf("\n4:exit\n");
printf("\nenter your choice:-");
scanf("\n%d",&choice);
switch(choice)
{
case 1:push();
break;
case 2:pop();
break;
case 3:display();
break;
case 4:exit();
}
}while(choice);
}
void push()
{
char ch;
int size;
top=0;
printf("\nenter how many size:-");
scanf("%d",&size);
while(top<size)
{
printf("enter the element:-");
scanf("%d",&s[top]);
top=top+1;
printf("if you want to insert push the element(Y|N)");
fflush(stdin);
scanf("%c",&ch);
if(ch=='N')
break;
}
if(top==size)
printf("\ndata overflow");
}
void pop()
{
char ch;
if(top==-1)
{
printf("\nunderflow data");
exit();
}
top=top-1;
while(top>=0)
{
printf("\n the deleted element:-%d",s[top]);
top=top-1;
printf("\nif you want to delete pop the element(Y|N)");
fflush(stdin);
scanf("%c",&ch);
if(ch=='N')
break;
}
if(top==-1)
printf("\nunderflow data");
}
void display()
{
int i=0;
if(top<0)
{
printf("\nstack is empty");
exit();
}
printf("\nthe element of stacks are:-\n");
while(i<=top)
{
printf("%d\n",s[i]);
i++;
}
}
/*enter your choice:-1
enter how many size:-5
enter the element:-3
if you want to insert push the element(Y|N)Y
enter the element:-6
if you want to insert push the element(Y|N)Y
enter the element:-9
if you want to insert push the element(Y|N)N
1:push
2:pop
3:display
4:exit
enter your choice:-2
the deleted element:-9
if you want to delete pop the element(Y|N)Y
the deleted element:-6
if you want to delete pop the element(Y|N)N
1:push
2:pop
3:display
4:exit
enter your choice:-3
the element of stacks are:-
3
1:push
2:pop
3:display
4:exit
enter your choice:-
4
*/
/*enter the element:-6
if you want to insert push the element(Y|N)Y
enter the element:-9
if you want to insert push the element(Y|N)Y
enter the element:-8
if you want to insert push the element(Y|N)Y
data overflow
1:push
2:pop
3:display
4:exit
enter your choice:-2
the deleted element:-8
if you want to delete pop the element(Y|N)Y
the deleted element:-9
if you want to delete pop the element(Y|N)N
1:push
2:pop
3:display
4:exit
enter your choice:-3
the element of stacks are:-
3
2
6
1:push
2:pop
3:display
4:exit
enter your choice:-
4
*/
No comments:
Post a Comment