Program for Stack Using switch( PUSH POP DISPLAY and MAKE EMPLY

Program for Stack Using switch( PUSH POP DISPLAY and MAKE EMPLY)+C programming

Here is the program of stack using the array; 1. push
2. pop
3. display 
4. empty

Follow our site for more  program 


.......................................
#include<stdio.h>
#include<process.h>
#include<conio.h>
#define max 3

int a[max];
int tos=-1;
int push();
int pop();
int disp();
int mkemp();
int main()
{
 int a;
 top:
 printf("Enter your choice\n1)PUSH\n2)POP\n3)DISPLAY\n4)MAKE EMPTY\n5)EXIT");
 scanf("%d",&a);
 switch(a)
{
case 1:

push();
break;

case 2:

pop();
break;

case 3:

disp();
break;

case 4:

mkemp();

case 5:

exit(0);
default:
printf("input error");

goto top;
       }

getch();
}

int push()
{
q:
int num;
if(tos==max-1)
{
printf("The satck is full");
}
else
{
printf("enter the number");
scanf("%d",&num);
tos++;
a[tos]=num;
printf("Insertion is sucessful");
goto q;
}
}
int pop()
{
if(tos==-1)
{
printf("Stack under flow");
}
else
{
return a[tos];
printf("The value is poped");
tos=tos-1;
}
}
int disp()
{
int i;
if(tos==-1)
{
printf("Stack empty");
}
else
{
for (i=0;i<tos;i++)
{
printf("%d\t",a[tos]);
}
}
}
int mkemp()
{
tos=-1;
printf("Now Stack is Empty");
}

Powered by Blogger.