How can one find a cycle in the linked list? IF found how
to recognize the cycle and delete that cycle?

Answer Posted / rajdeep...

void cycle_detect(struct node *head)
{
struct node *ptr1=head;
struct node *ptr2=head;
while(ptr1!=NULL && ptr1->next!=ptr2)
{
ptr1=ptr1->next;
}
if(ptr1->next==ptr2)
{
printf("the list contains cycle");
}
else
{
printf("the list don't contain cycle");
}
}

Is This Answer Correct ?    6 Yes 16 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can you tell me the differences between Array and ArrayList?

775


What is significance of ” * ” ?

793


Why is hashmap used?

675


Why is an array homogeneous?

622


Can a hashmap have duplicate keys?

689


Which is better selection or bubble sort?

660


What does the dummy header in the linked list contain?

931


Does treeset remove duplicates?

679


Explain the Stack

725


What are the different types of data type?

709


What sorting algorithm does arrays sort use?

615


Where will be the free node available while inserting a new node in a linked list?

744


Explain binary tree traversals?

677


Define structure property in a heap?

740


There is a program which inserts and deletes node in a sorted singly linked list. There is a bug in one of the modules, how would you debug it?

1507