Saturday, June 12, 2024

Basic Pop Operation On Stack : Remove Element from Stack





Basic Pop Operation On Stack : Data Structure

[ Watch Pop Operation Video On Youtube Pop Operation : Removing element from stack and decrementing top is called as "Pop Operation" .
Watch Following Video :

Pop Operation Arguments and Return Type :
  1. Argument  :  Variable of Type Stack.
  2. Return Type : Integer [ Removed Element ]
Steps in Pop Operation :
  1. Store Topmost Element in another Variable.
  2. Decrement Top by 1 
  3. Return Topmost Element .
Pre-requisites : Stack Type Definition .: Click Here
Pop Function :
int pop(stack *s)
{
int x;
  x = s->data[s->top];
  s->top = s->top - 1;
  return(x);
}

Note :
  1. Before Removing or Popping element from stack ensure that stack is not empty.
  2. Removing element from empty stack leads to problem called "Underflow of Stack"
How to Check Whether Stack is Empty of Not ?

Way 1 : Checking Inside pop()
int pop(stack *s)
{
int x;
  if(s->top == -1)
     {
     printf("Stack is Empty");
     exit(0);
     }
  x = s->data[s->top];
  s->top = s->top - 1;
  return(x);
}

Way 2 : Calling Independent empty()
int empty(stack *s)
{
  if(s->top == -1)
      return(1);
  else
      return(0);
}

Tags / Keywords : | , , ,

Stumble
Delicious
Technorati
Twitter
Facebook

0 Comments:

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email

 

Learn C Programming Copyright © 2010 LKart Theme is Designed by Lasantha, Free Blogger Templates