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 are the 3 types of variables?
What are the advantages of merge sort?
How to check array contains value or not?
What is a vector class?
How do you sort an array in descending order?
Can you distinguish between ArrayList and Array?
If we try to add duplicate key to the hashmap, what will happen?
Mention the steps to insert data at the starting of a singly linked list?
What is difference between map and hashmap?
How hashmap increases its size?
Which sort algorithm is best?
Can we change load factor of hashmap?
Why is data structure important?
What is thread and types of thread?
Define a set?