Done By: Prof.Dhumane A.V. VIIT, Pune
*/
#include
#include
int push(int *stack,int top)
{
int element;
if(top<9)
{
printf("\nEnter the element to be pushed");
scanf("%d",&element);
top++;
stack[top]=element;
}
else
{
printf("\n Stack FULL !!!");
}
return top;
}
int pop(int*stack,int top)
{
if(top>-1)
{
printf("\n Element %d poped ",stack[top]);
top--;
}
else
{
printf("\n Stack Empty !!!");
}
return top;
}
void display(int*stack,int top)
{
while(top>-1)
{
printf("%d ",stack[top]);
top--;
}
}
void main()
{
int stack[20],top=-1,choice;
clrscr();
while(1)
{
printf("\n1.PUSH");
printf("\n2.POP");
printf("\n3.Display");
printf("\n4.Exit");
printf("\nEnter your choice ");
scanf("%d",&choice);
switch(choice)
{
case 1: top=push(stack,top);
break;
case 2: top=pop(stack,top);
break;
case 3: display(stack,top);
break;
case 4:
exit(0);
}
}
}
No comments:
Post a Comment