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
Which collection class is thread safe?
Can a hashset contain duplicates?
Write an algorithm to check if there is a loop in a doubly linked list.
How do you do a heap sort?
What data type is array?
Explain the term base case?
What are basic algorithms?
What is the difference between an array and vector?
What is stack explain with diagram?
How will you reverse Linked List.
Can arraylist contain duplicates?
How to sort 1 million floating point numbers?
Does arraylist contain duplicates?
What is raid (redundant array of inexpensive disks)? Explain its level?
What are the different types of data structures explain briefly?