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

How does selection sort work?

945


What is binary search tree and explain its time complexity?

1006


Draw a binary Tree for the expression : A * B - (C + D) * (P / Q)

1474


Which is faster array or linked list?

955


Will this code give error if I try to add two heterogeneous elements in the arraylist? And why?

1001


What is difference between treeset hashset linkedhashset?

991


What is sorting with example?

961


How arraylist increase its size?

945


What is comparable interface?

1005


Can nsarray contain nil?

886


What are the four characteristics of algorithms?

931


List the basic operations carried out in a linked list?

1082


Why hashtable is faster than arraylist?

993


Can treeset contain null?

940


Define terminal nodes in a tree?

1090