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 -

  1. Function returns “True” if Stack is Full
  2. Function returns “False” if Stack is Not Full.
  3. Function Takes “Pointer to Stack”
int full (stack *s)
  1. Return Type : Integer. [If full Stack Return 1 , not full Stack Return 0 ]
  2. 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
------
------
}
  1. Pass “Stack” Variable to “full Function” using pass by reference.
  2. 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);
}