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

Name few concurrent collection classes?

685


What is the difference between arraylist and linkedlist?

671


Why it is important to have aligned addresses? What is the exception generated when there is a misaligned address?

692


Which is faster quick sort or merge sort?

634


How to sort an Array?

719


What are the types of collision resolution strategies in open addressing?

772


How do you initialize an arraylist?

681


What is the method to find the complexity of an algorithm?

767


Differentiate between list and set.

837


What is a priority queue?

730


What does map stand for?

638


Is pointer a variable in data structure?

746


What is a dequeue?

729


Define hash function?

695


What is return map?

734