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?
How does a selection sort work for an array?
Is treemap thread safe?
What is a data structure definition?
How does quick sort work?
Is quicksort recursive?
Can arraylist have null values?
What is linked list ?
What is advantage and disadvantage of linked list?
Which sorting algorithm is used in collections sort?
What is difference between static and dynamic array?
What is meant by deque?
How does a dynamic array work?
What does stack top do?
What is concept of data structure?