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
What is the use of hashtable?
Why do we use insertion sort?
Can sets contain duplicates?
What is the difference between hashmap and arraylist?
How many types of data structures are there?
Who created quicksort?
Explain the expression trees?
What is adt and its advantages?
In what areas do data structures are applied?
Why do we use dynamic arrays?
How do I sort a hashmap key?
Is priority queue sorted?
What are the different types of data structures?
What do you mean by secondary clustering?
Is it possible to increase size of array?