#include
int top = 0,nos,stak[50],temp;
void push();
void pop();
void traverse();
main()
{
int opt;
printf("Enter the stack size");
scanf("%d",&nos);
do
{
printf("1. PUSH");
printf("2. POP");
printf("3. TRAVERSE");
printf("4. EXIT");
printf("Enter any one of ur option");
scanf("%d", &opt);
switch(opt)
{
case 1: push();
break;
case 2: pop();
break;
case 3: traverse();
break;
}
}while(opt !=4);
getch();
}
void push()
{
if (top
top = top +1;
printf("Element to be inserted...");
scanf("%d",&temp);
stak[top] = temp;
}
else
printf("Stack is full");
}
void pop()
{
if (top !=0)
{
temp = stak[top];
printf("The poped element id %d", temp);
top = top -1;
}
else
printf("Stack is Empty");
}
void traverse()
{
int i;
if (top !=0)
{
for(i=top; i>=1; --i)
printf("%d\n"stak[i]);
}
else
printf("Stack is Empty");
}
No comments:
Post a Comment