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 is the height of a binary tree?
What is difference between map and hashmap?
Why is data structure?
What are the tasks performed during preorder traversal?
Is arraylist a collection?
What is difference between list and array list?
What are the applications of stack?
Does hashmap preserve insertion order?
Explain extended binary tree.
What is the difference between arraylist and array?
Is arraylist reference type?
What are the advantages of linked list over an array?
What is a multidimensional array?
What is bubble sort in data structure?
Why do we use trees in data structures?