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

Answer Posted / vishal

a cycle is not only a link between the last node of list and
the first node of the list ..but a cycle can also be present
from the last node to the second,third,fourth node of the
list....

implementing using recursive functions.....
boolean hasloop(struct node *start)
{
if(start!=NULL)//stop condition for recursive function
{
currentnode=start;
while(currentnode!=NULL)
{
currentnode=currentnode->link;
if(start==currentnode)//cycle detected
{
return true;
}
}
}

return false;//cycle not detected

}

Is This Answer Correct ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the height of a binary tree?

681


What is difference between map and hashmap?

674


Why is data structure?

639


What are the tasks performed during preorder traversal?

798


Is arraylist a collection?

688


What is difference between list and array list?

629


What are the applications of stack?

683


Does hashmap preserve insertion order?

668


Explain extended binary tree.

717


What is the difference between arraylist and array?

672


Is arraylist reference type?

640


What are the advantages of linked list over an array?

721


What is a multidimensional array?

698


What is bubble sort in data structure?

675


Why do we use trees in data structures?

666