Check Whether Stack is Full or Not ?
Check Whether Stack is Full or Not ?
We are using Empty Function for Checking whether stack is full or not -
- Function returns “True” if Stack is Full
- Function returns “False” if Stack is Not Full.
- Function Takes “Pointer to Stack”
int full (stack *s)
- Return Type : Integer. [If full Stack Return 1 , not full Stack Return 0 ]
- Parameter : Address of Variable of Type Stack .
How to Call this Function From Main ?
typedef struct stack { int data[MAX]; int top; }stack; void main() { stack s; // Declare Stack Variable ------- ------- i = full(&s); // Pass By Reference ------ ------ }
- Pass “Stack” Variable to “full Function” using pass by reference.
- As full Function returns integer , we have facility to store returned value into some integer variable so we have written [ i = full(&s) ]
Complete Code
int full(stack *s) { if(s->top == MAX-1) //Stack is Full return(1); else return(0); }