Program to implement stack operations

int a[10],top;
void main()
{
int ch;
clrscr();
top=-1;
while(1)
{
printf("\n\t\t****MENU****\n");
printf("\n 1.Push\n 2.Pop\n 3.Display \n 4.Exit");
printf("\n\n Enter your Choice :");
scanf("%d",&ch);
switch(ch)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
exit();
}//switch
}//while
}

push()
{
int item;
printf("\n enter The Number You want to push :");
scanf("%d",&item);
if(top==9)
{
printf("\n overflow-You can't push");
}
else
{
top=top+1;
a[top]=item;
}
}//push

pop()
{
int item;
if(top<0) item="a[top];" top="top-1;" i="top;i">=0;i--)
{
printf("\n %d",a[i]);
}
}//display

0 comments: