Stack Push Operation : Insert Element Onto StackPritesh
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 :
- Push Refers as “Adding Elements onto Stack“.
- 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.
- Main Function Should ensure that stack is not full before making call to push() in order to prevent “Stack Overflow“
void push(stack *s,int num)
s->top = s->top + 1;
s->data[s->top] = num;
What is Stack Overflow ?
- Pushing element onto stack which is already filled is refer as “Stack Overflow“.
- 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