#include<stdio.h>
#include<conio.h>
#define SIZE 10
int stack[SIZE];
int top=-1;
void main()
{
void push(int);
int pop();
void show();
int choice,item;
while(1)
{
clrscr();
printf("\n1. Push an Item");
printf("\n2. Pop an Item");
printf("\n3. Display Stack");
printf("\n4. Exit");
printf("\nEnter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\nEnter number : ");
scanf("%d",&item);
push(item);
break;
case 2:
item=pop();
break;
case 3:
show();
break;
case 4:
exit(0);
default:
printf("\nWron Input.....");
getch();
}
}
}
void push(int item)
{
if(top>=SIZE)
{
printf("\nStack is Full");
getch();
}
else
{
top++;
stack[top]=item;
printf("\nItem is pushed");
getch();
}
}
int pop()
{
int item;
if(top<0)
{
printf("\nStack is Empty");
getch();
}
else
{
item=stack[top];
top--;
printf("\nItem %d popped",item);
getch();
}
return(item);
}
void show()
{
int i;
if(top<0)
{
printf("\nStack is Empty");
getch();
}
else
{
printf("\nStack Elements : ");
for(i=0;i<=top;i++)
{
printf("%d ",stack[i]);
}
getch();
}
}
No comments:
Post a Comment