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 are linked lists used for?

526


Which is faster list or set?

476


Define level of the tree?

560


Is a hashmap a dictionary?

459


What is time and space complexity of bubble sort?

440






How do you replace an element in an arraylist?

519


Can arraylist hold different types?

475


For addition and deletion. Which one is most preferred: array list or linked list?

508


How do you sort elements in an arraylist?

464


What is a stable algorithm?

470


Is list an array?

434


What do you mean by priority queue?

491


Why is hashmap used?

507


What is default array size?

552


Define graph traversals?

530