What is Stack ?
Stack is a linear data structure which follows a particular order in which the operations are performed.
The order may be LIFO(Last In First Out) or FILO(First In Last Out).
What is pop operation in Stack ?
-Deletion in stack is called the pop operation in stack.
-Deletion in stack is done on the top of the stack.
Function for pop() function:
void pop()
{
if(top==-1)
{
printf("Stack is Underflow");
return 0;
}
stack[top]='';
top--;
}
#include< stdio.h>
#include< conio.h>
#define max 50
int stack[max],top=-1;
void create()
{
char ch;
do
{
top++;
printf("Enter Number\n");
scanf("%d",&stack[top]);
printf("Continue(y/n)\n");
ch=getch();
}while(ch=='y');
}
void traverse()
{
int i;
printf("Stack is :\n");
for(i=top;i>=0;i--){
printf("%d ",stack[i]);
}
}
void pop()
{
if(top==-1)
{
printf("Stack is Underflow");
return 0;
}
stack[top]='';
top--;
}
void main()
{
clrscr();
create();
traverse();
pop();
printf("After pop operation\n");
traverse();
getch();
}
Enter Number
3
Continue(y/n)?
Enter Number
4
Continue(y/n)?
Enter Number
5
Continue(y/n)?
Enter Number
8
Continue(y/n)?
Stack is :
8 5 4 3
After pop operation
Stack is :
5 4 3