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 immutablelist?
For the following COBOL code, draw the Binary tree? 01 STUDENT_REC. 02 NAME. 03 FIRST_NAME PIC X(10). 03 LAST_NAME PIC X(10). 02 YEAR_OF_STUDY. 03 FIRST_SEM PIC XX. 03 SECOND_SEM PIC XX.
What is the difference between an array and vector?
Difference between calloc and malloc ?
What are threaded binary trees?
What is queue in data structure?
What is the advantage of the heap over a stack?
How expression trees are gets represented in data structure?
What is weight balanced tree in data structure?
What do you mean by balance factor of a node in avl tree?
Does arraylist maintain insertion order?
what are the applications of Linked Lists?
What is a treemap used for?
What is unmodifiable list?
What is difference between concurrenthashmap and hashtable?