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


Please Help Members By Posting Answers For Below Questions

What is a pseudocode example?

492


What is the difference between dictionary and hashtable?

514


Can we insert null in list?

501


What is the use of treemap?

484


what is the difference between singly and doubly linked lists?

541






What is hashing technique?

545


Define probing?

708


Define a binary tree?

563


Explain circular linked list?

534


What do you mean by Syntax Error

562


What is the impact of signed numbers on the memory?

537


What is map keyset?

469


What are the types of sorting?

483


Does treemap preserve order?

468


What do you mean by shortest path?

540