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 modcount in hashmap?
Can a binary tree be empty?
What is an recursive algorithm?
How can we delete the first node from the singly linked list?
What is linear and non linear structure?
What is array and its types?
How can you correct these errors?
What are dynamic data structures?
Differentiate linear from a nonlinear data structure?
What is a stable algorithm?
Is treemap synchronized?
Will it create any problem if we add elements with key as user defined object into the treemap?
Can you override methods of arraylist?
Why is data structure?
Which is better hashmap or hashtable?