Right Click to Search

Saturday, June 12, 2024

Basic Push Operation on Stack : Insert Element Onto Stack



Push Operation On Stack

Tags : Push Operation , Data Structure Push Operation : Before Starting with Push Operation , Let us First make it clear , "How Stack Push Operation Works ?"


Push Operation :
  1. Push Refers as "Adding Elements onto Stack".
  2. Push Operation carried out in following 2 steps -
    • First Increment Variable "top" so that it now refers to next memory location.
    • Secondly Add Element Onto Stack by accessing array.
  3. Main Function Should ensure that stack is not full before making call to push() in order to prevent "Stack Overflow"
Push Function
void push(stack *s,int num)
{
s->top = s->top + 1;
s->data[s->top] = num;
}
What is Stack Overflow ?
  1. Pushing element onto stack which is already filled is refer as "Stack Overflow".
  2. Using array representation of stack ,variable "MAX" is used to keep track of "Number of Maximum Elements"
How to Check Whether Stack is Full or not ?
int full(stack *s)
{
  if(s->top == MAX-1) //Stack is Full
     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