How can one find a cycle in the linked list? IF found how
to recognize the cycle and delete that cycle?
Answer Posted / monti
bool find_cycle(Node* head){
Node* ptr1 = head;
Node* ptr2 = head;
while(ptr1 != NULL && ptr2 != NULL && ptr2->next != NULL){
if(ptr1 == ptr2){
printf("\nClycle present in thr LinkList\n");
return true;
}
ptr1 = prt1->next;
ptr2 = ptr2->next->next;
}
return false;
}
| Is This Answer Correct ? | 36 Yes | 14 No |
Post New Answer View All Answers
How does selection sort work?
What is binary search tree and explain its time complexity?
Draw a binary Tree for the expression : A * B - (C + D) * (P / Q)
Which is faster array or linked list?
Will this code give error if I try to add two heterogeneous elements in the arraylist? And why?
What is difference between treeset hashset linkedhashset?
What is sorting with example?
How arraylist increase its size?
What is comparable interface?
Can nsarray contain nil?
What are the four characteristics of algorithms?
List the basic operations carried out in a linked list?
Why hashtable is faster than arraylist?
Can treeset contain null?
Define terminal nodes in a tree?