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

How do you sort large data?

657


What are the disadvantages of using collection classes over arrays?

587


What is the use of sorting the data?

623


Is unordered_map a hash table?

557


What are the applications of b-tree?

632






Can we extend an array after initialization?

661


Can we store a string and integer together in an array?

539


What do you mean by sorting?

524


How dynamic arrays are created?

546


What is the default capacity of hashmap?

500


What is complexity of quicksort?

611


Why do we use binary search?

565


Can we modify final arraylist?

600


Is boolean a data type?

532


Is quicksort greedy algorithm?

591