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
Is bubble sort faster than selection sort?
Why do we use hashmap?
You are given a singly linked list. How would you find out if it contains a loop or not without using temporary space?
What is modcount in hashmap?
What are the disadvantages of circular list?
which notations are used in evaluation of arithmetic expressions using prefix and postfix forms?
How would you dynamically allocate a one-dimensional and two-dimensional array of integers?
Explain what are the major data structures used in the network data model?
What is the best complexity of bubble sort?
Is binary tree a bst?
What are the advantages of bubble sort?
How does a dynamic array work?
What is an iterative algorithm?
Write a Program for Delete an element from a doubly linked list.
What is adt and its advantages?