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
Can you tell me the differences between Array and ArrayList?
What is significance of ” * ” ?
Why is hashmap used?
Why is an array homogeneous?
Can a hashmap have duplicate keys?
Which is better selection or bubble sort?
What does the dummy header in the linked list contain?
Does treeset remove duplicates?
Explain the Stack
What are the different types of data type?
What sorting algorithm does arrays sort use?
Where will be the free node available while inserting a new node in a linked list?
Explain binary tree traversals?
Define structure property in a heap?
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?