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
What does a bubble chart show?
Can arraylist have duplicates?
What is meant by linked list?
What is the difference between a hashmap and hashtable?
What is a string or array type?
Write an algorithm for inserting and deleting an element from doubly linked list?
Which sorting algorithm is considered the fastest?
What does arrays tostring do?
Which interfaces are implemented by printerstatereasons?
Why is hashing used?
What is adt and its advantages?
What are the advantages of merge sort?
What is the difference between the hash table and hash map?
What is faster array or arraylist?
What is the best case for bubble sort?