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

Is hashmap faster than arraylist?

535


For the following COBOL code, draw the Binary tree? 01 STUDENT_REC. 02 NAME. 03 FIRST_NAME PIC X(10). 03 LAST_NAME PIC X(10). 02 YEAR_OF_STUDY. 03 FIRST_SEM PIC XX. 03 SECOND_SEM PIC XX.

915


Why is hashmap faster than arraylist?

615


What is binary search in programming?

571


Are linked lists considered linear or non-linear data structure?

697






What are the collision resolution methods?

613


How can someone display singly linked list from first to last?

578


What is basic data structure?

581


Explain linear linked implementation of Stack and Queue?

610


What is meant by balanced binary tree?

567


When new data are to be inserted into a data structure?

569


Can hashset contain duplicates?

562


Differentiate between iterable and iterator.

746


Traverse the given tree using Inorder, Preorder and Postorder traversals. Inorder : D H B E A F C I G J Preorder: A B D H E C F G I J Postorder: H D E B F I J G C A

731


Is arraylist fail fast?

573