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


Please Help Members By Posting Answers For Below Questions

What is the difference between sorting and classifying?

483


Explain quick sort and merge sort algorithms.

579


Which language is best for data structures and algorithms?

504


Explain stacks and queues in detail.

735


What is difference between set and map?

513






What are the collision resolution methods?

539


Why do we need to use computers to help us sort lists?

575


How do you find the space complexity of a bubble sort?

496


What are the types of binary tree?

502


What is raid (redundant array of inexpensive disks)? Explain its level?

480


Is complete binary tree?

487


Differentiate between an array and an arraylist.

584


Explain extended binary tree.

515


Write the algorithm for converting infix expression to postfix expression?

564


Tell me why can't constant values be used to define an array's initial size

532