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
What are the disadvantages of using collection classes over arrays?
Write the stack overflow condition.
Which is better hashmap or arraylist?
What is complexity of bubble sort?
What is a sorting algorithm in data structure?
Which sorting algorithm uses minimum number of swaps?
Is hashtable fail fast?
How to use appendNode() in linkedlist()?
Why do we use collections?
What is the main advantage of a linked list?
Why we use arraylist instead of linked list?
Define back edge?
What do you mean by heap order property?
Can we search the data in a linked list?
Which algorithm is used in arrays sort?