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 is a pseudocode example?
What is the difference between dictionary and hashtable?
Can we insert null in list?
What is the use of treemap?
what is the difference between singly and doubly linked lists?
What is hashing technique?
Define probing?
Define a binary tree?
Explain circular linked list?
What do you mean by Syntax Error
What is the impact of signed numbers on the memory?
What is map keyset?
What are the types of sorting?
Does treemap preserve order?
What do you mean by shortest path?