Pop operation in Stack

http://install4install.com

POP Operation

In this  operation topmost element is deleted from the stack.Before deleting check if TOP = NULL.If yes,it means that stack is empty and no deletion can be done.If an attempt to delete element is made in this case the UNDERFLOW message will be printed on screen.If no,then element is deleted then value of TOP is decremented by 1.

For example

 

Screen Shot 2014-04-08 at 5.17.45 PM

Fig 9 : Pop Operation in Stack

Program 2

#include<stdio.h>

int main()
{
	int max;
	int stack[10];
	int num,val,i,temp;
	int top = -1;
	//printf("Enter the maximum size of stack");
	scanf("%d",&max);
	//printf("Enter the no of elements in stack");
	scanf("%d",&num);
	//printf("Enter the elements of stack");
	for(i=0;i<num;i++)
	{
		scanf("%d\n",&stack[i]);
		top++;
	}
	temp =top;
	if(top == -1)
	{
		printf("Underflow");
	}
	else
	{
		top =top -1;
		printf("The stack after pop operation is \n");
		for(i=0;i<temp;i++)
		{
		 printf("%d\n",stack[i]);
		top++;
	}
	}
	return 0;
}

Run
 Illustration of Program 2



Short URL: http://tinyit.cc/dd0e98
Author: Cusp2207 on July 18, 2014
Category: Algorithms, Computer Science, Data Structures
Tags:

Leave a Reply

Last articles