Can you tell me how to check whether a linked list is circular?

Can you tell me how to check whether a linked list is circular?

First you have to Create two pointers, each set to the start of the list. And Update each as below:

while (pointer1) {
    pointer1 = pointer1->next;
    pointer2 = pointer2->next; 
if (pointer2)   
    pointer2=pointer2->next;
if (pointer1 == pointer2) {
    print (\"circular\n\");
}
}

By:Vivek Kr. Agarwal
Date:2029-12-08 00:00:00

Node *HeadData;
Node *TempData;
TempData = HeadData;

do
{
if (HeadData == TempData->next)
break;
 TempData = TempData->next;
}while(TempData);



By:karthiken07
Date:0000-00-00 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related C Subjective Links

C Subjective interview questions and answers for experienced and fresher