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
Is hashmap fail safe?
What is ascending and descending order?
What is data structure definition?
What is the best data structure and algorithm to implement cache?
What is a data structure definition?
Is arraylist a collection?
What is the height of an empty tree?
What is difference between list and array list?
Define b-tree of order m?
What is worst case complexity algorithm?
What are the properties of binary heap?
Describe the complexity of Quick Sort
Define a full binary tree ?
Which is the parent class of abstractqueue class?
What are the advantages of modularity?