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 / rajdeep...

void cycle_detect(struct node *head)
{
struct node *ptr1=head;
struct node *ptr2=head;
while(ptr1!=NULL && ptr1->next!=ptr2)
{
ptr1=ptr1->next;
}
if(ptr1->next==ptr2)
{
printf("the list contains cycle");
}
else
{
printf("the list don't contain cycle");
}
}

Is This Answer Correct ?    6 Yes 16 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Tell me what should be done in the base case for this recursive problem?

938


How do you sort elements in an arraylist?

924


Are linked lists useful?

953


Tell me is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?

976


What is faster array or arraylist?

955


Briefly explain recursive algorithm?

1078


Can hashmap have same key?

921


What is a list of lists?

977


What is the procedure to insert into a sorted array?

1043


Difference between arraylist and linkedlist?

1064


Which collection allows null values?

938


What does a treemap do?

890


How do you find the index of an element in an arraylist?

930


How to pass in data structure exam?

1077


What is a property class?

1087