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
Name few concurrent collection classes?
What is the difference between arraylist and linkedlist?
Why it is important to have aligned addresses? What is the exception generated when there is a misaligned address?
Which is faster quick sort or merge sort?
How to sort an Array?
What are the types of collision resolution strategies in open addressing?
How do you initialize an arraylist?
What is the method to find the complexity of an algorithm?
Differentiate between list and set.
What is a priority queue?
What does map stand for?
Is pointer a variable in data structure?
What is a dequeue?
Define hash function?
What is return map?