Data Structures Question:

Download Job Interview Questions and Answers PDF

Tell how to check whether a linked list is circular ?

Data Structures Interview Question
Data Structures Interview Question

Answer:

Create two pointers, each set to the start of the list. Update each as follows:

while (pointer1)

{
pointer1 = pointer1->next;
pointer2 = pointer2->next; if (pointer2) pointer2=pointer2->next;
if (pointer1 == pointer2)

? ? ? ? ? ? {
print (”circularn”);
}
}

Download Data Structures Interview Questions And Answers PDF

Previous QuestionNext Question
What is placement new in data structures?What is the difference between ARRAY and STACK in Data Structures?