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 linked lists used for?
Which is faster list or set?
Define level of the tree?
Is a hashmap a dictionary?
What is time and space complexity of bubble sort?
How do you replace an element in an arraylist?
Can arraylist hold different types?
For addition and deletion. Which one is most preferred: array list or linked list?
How do you sort elements in an arraylist?
What is a stable algorithm?
Is list an array?
What do you mean by priority queue?
Why is hashmap used?
What is default array size?
Define graph traversals?