#include<stdio.h>
#define SIZE 5
int stack[SIZE];
int top;
void PUSH();
void POP();
void DISPLAY();
void STACK_COUNT();
void EXIT();
void main()
{
int CHOICE;
while(1)
{
printf("MAIN MENU \n\n 1.PUSH \n 2.POP \n 3.DISPLAY \n 4.STACK COUNT \n5.EXIT \n\nENTER YOUR CHOICE:");
scanf("%d",&CHOICE);
switch(CHOICE)
{
case 1:
PUSH();
break;
case 2:
POP();
break;
case 3:
DISPLAY();
break;
case 4:
STACK_COUNT();
break;
case 5:
EXIT();
break;
default:
printf("\nWRONG CHOISE");
}
}
}
void PUSH()
{
if(top>=SIZE)
{
printf("STACK IS FULL\n\n");
return;
}
else
{
if(top<=0)
top=0;
printf("\nENTER THE ELEMENT:");
scanf("%d",&stack[top++]);
}
}
void POP()
{
if(top<=0)
printf("\nSTACK IS EMPTY\n\n");
else
{
printf("\nPOPED ELEMENT:%d\n\n",stack[--top]);
}
}
void DISPLAY()
{
int i;
if(top<=0)
printf("\nSTACK IS EMPTY\n");
else
{
for(i=(top-1);i>=0;i--)
{
if(i==(top-1))
printf("----> TOP ELEMENT\n");
printf("%d \n",stack[i]);
}
printf("\n");
}
}
void STACK_COUNT()
{
if(top<=0)
printf("STACK IS EMPTY\n\n");
else
{
printf("STACK IS EMPTY WITH %d ELEMENTS\n\n",(SIZE-(top-1)));
}
}
void EXIT()
{
exit(0);
}
#define SIZE 5
int stack[SIZE];
int top;
void PUSH();
void POP();
void DISPLAY();
void STACK_COUNT();
void EXIT();
void main()
{
int CHOICE;
while(1)
{
printf("MAIN MENU \n\n 1.PUSH \n 2.POP \n 3.DISPLAY \n 4.STACK COUNT \n5.EXIT \n\nENTER YOUR CHOICE:");
scanf("%d",&CHOICE);
switch(CHOICE)
{
case 1:
PUSH();
break;
case 2:
POP();
break;
case 3:
DISPLAY();
break;
case 4:
STACK_COUNT();
break;
case 5:
EXIT();
break;
default:
printf("\nWRONG CHOISE");
}
}
}
void PUSH()
{
if(top>=SIZE)
{
printf("STACK IS FULL\n\n");
return;
}
else
{
if(top<=0)
top=0;
printf("\nENTER THE ELEMENT:");
scanf("%d",&stack[top++]);
}
}
void POP()
{
if(top<=0)
printf("\nSTACK IS EMPTY\n\n");
else
{
printf("\nPOPED ELEMENT:%d\n\n",stack[--top]);
}
}
void DISPLAY()
{
int i;
if(top<=0)
printf("\nSTACK IS EMPTY\n");
else
{
for(i=(top-1);i>=0;i--)
{
if(i==(top-1))
printf("----> TOP ELEMENT\n");
printf("%d \n",stack[i]);
}
printf("\n");
}
}
void STACK_COUNT()
{
if(top<=0)
printf("STACK IS EMPTY\n\n");
else
{
printf("STACK IS EMPTY WITH %d ELEMENTS\n\n",(SIZE-(top-1)));
}
}
void EXIT()
{
exit(0);
}
No comments:
Post a Comment