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 advantages of binary search over linear search?
What is map data structure?
Can the double-checked locking fail on a single processor system?
Define balanced trees?
Can we give size to arraylist?
Find duplicates in infinite range. Which data structure to be used to give efficient solution?
What is hash value of a string?
Which sorting method is slowest?
What is dynamic array with example?
What are the disadvantages of using collection classes over arrays?
List some applications of queue data structure.
Which sorting has less time complexity?
Differentiate between arraylist and linkedlist.
Define indegree of a graph?
Explain the term binding time?