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 to fing linkedlist is circular or not?

Answer Posted / pradip mishra(b-tech it)

Create two pointers, each set to the start of the list.
Update each as follows:

while (pointer1) {
pointer1 = pointer1->next;
pointer2 = pointer2->next; if (pointer2)
pointer2=pointer2->next;
if (pointer1 == pointer2) {
print (\"circular\n\");
}
}

If a list is circular, at some point pointer2 will wrap
around and be either at the item just before pointer1, or
the item before that. Either way, it?s either 1 or 2 jumps
until they meet.

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Describe the various concepts related to object oriented programming (oop).

985


Explain the significance of listiterator.

1036


How do singleton patterns work?

924


How we can generate random numbers in java?

1091


In how many ways we can do exception handling in java?

941


How is tree Mirroring implemented?

1011


How do you override a method?

966


How do you sort objects in java?

915


From the two, which would be easier to write: synchronization code for ten threads or two threads?

1010


Implement two stacks using a single array.

1012


How can we achieve thread safety in java?

1095


What is string and example?

991


What is a loop java?

1013


What is a databasemetadata?

903


What is foreach loop in java?

963