in DS recategorized by
676 views
7 votes
7 votes

Consider the following function fun() that takes the head of a linked list.

struct node {
    int value;
    struct node *next;
};
typedef struct node Node;

int fun(Node *head){
    if(head== NULL) return 1;
    Node *p,*q;
    p = head;
    q = p->next;
    while(q!=NULL && q!=p){
        q = q->next;
    if(q==NULL) return 1;
    q = q->next;
    p = p->next;
    }
return (q==NULL);
}


We say, a linked list has a loop if the last node of linked list points to some node of linked list and does not point to NULL.

What does the above function do?

  1. Returns $0$ is there is loop in linked list
  2. Returns $1$ is there is loop in linked list
  3. Returns $0$ is length of the linked list is even
  4. Function may go to infinite loop if there is a loop in linked list
in DS recategorized by
676 views

1 Answer

6 votes
6 votes

Answer will be option A 

we will also see why some options are not correct

2 Comments

Hey try to use contrasting colors from next time, it is hard to read.

1
1
Use yellow.
0
0
Answer:

Related questions