Right Click to Search

Friday, June 11, 2024

Check Whether Stack is Empty or Not ? : Data Structure





Check Whether Stack is Empty or Not ?

We are using Empty Function for Checking whether stack is empty or not -
  1. Function returns "True" if Stack is Empty.
  2. Function returns "False" if Stack is Non-Empty.
  3. Function Takes "Pointer to Stack"
int empty (stack *s)
  1. Return Type : Integer. [Empty Stack Return 1 , Non Empty 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; // Step 1 : Declare Variable of Type Stack
-------
-------
-------  
-------
-------
-------  
i = empty(&s);   // Pass By Reference
------
------
}
  1. Pass "Stack" Variable to "Empty Function"  using pass by reference.
  2. As Empty Function returns integer , we have facility to store returned value into some integer variable so we have written [ i = empty(&s) ]

Empty Function :
int empty(stack *s)
{
  if(s->top == -1) //Stack is Empty
     return(1);
  else
     return(0);
}stack;

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