#include<stdio.h>
#include<conio.h>
int stack[100],tos=-1;
void main()
{
int ch;
do
{
clrscr();
printf("\n Stack ");
printf("\n 1. PUSH");
printf("\n 2. POP");
printf("\n 3. PEEP");
printf("\n 4. DISPLAY");
printf("\n 5. Exit");
printf("\n Enter your choice :");
scanf("%d",&ch);
switch(ch)
{
case 1:
push();
getch();
continue;
case 2:
pop();
getch();
continue;
case 3:
peep();
getch();
continue;
case 4:
display();
getch();
continue;
}
}while(ch!=5);
}
push()
{
int x;
if(tos==99)
{
printf("\n Stack is Full");
return;
}
printf("\n Enter value : ");
scanf("%d",&x);
stack[++tos] = x;
return;
}
pop()
{
int x;
if(tos==-1)
{
printf("\n Stack is Empty");
return;
}
x = stack[tos--];
printf("\n Element popped ... %d",x);
return;
}
peep()
{
if(tos==-1)
{
printf("\n Stack is Empty");
return;
}
printf("\n Element on top of the stack : %d",stack[tos]);
return;
}
display()
{
int x;
if(tos==-1)
{
printf("\n Stack is Empty");
return;
}
for(x=tos;x>=0;x--)
printf("\n Element on stack[%d] is : %d",x+1,stack[x]);
return;
}
#include<conio.h>
int stack[100],tos=-1;
void main()
{
int ch;
do
{
clrscr();
printf("\n Stack ");
printf("\n 1. PUSH");
printf("\n 2. POP");
printf("\n 3. PEEP");
printf("\n 4. DISPLAY");
printf("\n 5. Exit");
printf("\n Enter your choice :");
scanf("%d",&ch);
switch(ch)
{
case 1:
push();
getch();
continue;
case 2:
pop();
getch();
continue;
case 3:
peep();
getch();
continue;
case 4:
display();
getch();
continue;
}
}while(ch!=5);
}
push()
{
int x;
if(tos==99)
{
printf("\n Stack is Full");
return;
}
printf("\n Enter value : ");
scanf("%d",&x);
stack[++tos] = x;
return;
}
pop()
{
int x;
if(tos==-1)
{
printf("\n Stack is Empty");
return;
}
x = stack[tos--];
printf("\n Element popped ... %d",x);
return;
}
peep()
{
if(tos==-1)
{
printf("\n Stack is Empty");
return;
}
printf("\n Element on top of the stack : %d",stack[tos]);
return;
}
display()
{
int x;
if(tos==-1)
{
printf("\n Stack is Empty");
return;
}
for(x=tos;x>=0;x--)
printf("\n Element on stack[%d] is : %d",x+1,stack[x]);
return;
}
No comments:
Post a Comment