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 the difference between sorting and classifying?
Explain quick sort and merge sort algorithms.
Which language is best for data structures and algorithms?
Explain stacks and queues in detail.
What is difference between set and map?
What are the collision resolution methods?
Why do we need to use computers to help us sort lists?
How do you find the space complexity of a bubble sort?
What are the types of binary tree?
What is raid (redundant array of inexpensive disks)? Explain its level?
Is complete binary tree?
Differentiate between an array and an arraylist.
Explain extended binary tree.
Write the algorithm for converting infix expression to postfix expression?
Tell me why can't constant values be used to define an array's initial size