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 the use of hashtable?

487


Why do we use insertion sort?

476


Can sets contain duplicates?

448


What is the difference between hashmap and arraylist?

511


How many types of data structures are there?

514






Who created quicksort?

514


Explain the expression trees?

577


What is adt and its advantages?

554


In what areas do data structures are applied?

532


Why do we use dynamic arrays?

462


How do I sort a hashmap key?

493


Is priority queue sorted?

508


What are the different types of data structures?

520


What do you mean by secondary clustering?

522


Is it possible to increase size of array?

457