Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Which collection class is thread safe?

895


Can a hashset contain duplicates?

994


Write an algorithm to check if there is a loop in a doubly linked list.

991


How do you do a heap sort?

925


What data type is array?

957


Explain the term base case?

974


What are basic algorithms?

953


What is the difference between an array and vector?

1111


What is stack explain with diagram?

955


How will you reverse Linked List.

944


Can arraylist contain duplicates?

914


How to sort 1 million floating point numbers?

1262


Does arraylist contain duplicates?

939


What is raid (redundant array of inexpensive disks)? Explain its level?

970


What are the different types of data structures explain briefly?

1151