C functions precise to verify emptiness of Queue - Data Structure

Q.  Which of the following ' C ' functions is precise to verify the emptiness of a Queue?
- Published on 19 Oct 15

a.
int empty(Q*P)
{
if (P->R==-1)
return (1);
return(0);
}
b.
int full (Q*P)
{
if(P->R==MAX-1)
return(1);
return(0);
}
c.
int empty (Q*P)
{
if (P<-R==-1)
return(0);
return(1);
}
d.
int full (Q*P)
{
if(P<-R==MAX-1)
return(0);
return(1);
}

ANSWER:
int empty(Q*P)
{
if (P->R==-1)
return (1);
return(0);
}
 

    Discussion

  • Nirja Shah   -Posted on 16 Nov 15
    In the given example P is the pointer object and rear is represented by variable R.
    So if the queue is empty the value of rear should be -1.
    int empty(Q *P)
    {
        if (P→R==-1)
        return (1);
        return(0);
    }
    Here P→R== -1 represents that the value of rear is -1 and queue is empty.

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)