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 does a bubble chart show?

447


Can arraylist have duplicates?

512


What is meant by linked list?

470


What is the difference between a hashmap and hashtable?

430


What is a string or array type?

448






Write an algorithm for inserting and deleting an element from doubly linked list?

493


Which sorting algorithm is considered the fastest?

587


What does arrays tostring do?

470


Which interfaces are implemented by printerstatereasons?

504


Why is hashing used?

456


What is adt and its advantages?

554


What are the advantages of merge sort?

456


What is the difference between the hash table and hash map?

509


What is faster array or arraylist?

454


What is the best case for bubble sort?

472