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 hashmap faster than arraylist?
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.
Why is hashmap faster than arraylist?
What is binary search in programming?
Are linked lists considered linear or non-linear data structure?
What are the collision resolution methods?
How can someone display singly linked list from first to last?
What is basic data structure?
Explain linear linked implementation of Stack and Queue?
What is meant by balanced binary tree?
When new data are to be inserted into a data structure?
Can hashset contain duplicates?
Differentiate between iterable and iterator.
Traverse the given tree using Inorder, Preorder and Postorder traversals. Inorder : D H B E A F C I G J Preorder: A B D H E C F G I J Postorder: H D E B F I J G C A
Is arraylist fail fast?