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 a reverse linked list.
How do you find the complexity of a selection sort?
Why do we use a multidimensional array in data structure?
Does array sort mutate?
Explain what is linear search?
Is treemap thread safe?
What is a graph?
What are hashmaps good for?
Define a relation?
What is a simple graph?
How to search binary in a sorted array?
What do you mean by general trees?
What is a node in it?
Which is the parent class of deque
How does bogo sort work?