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

What is the difference between static class and normal class?

1032


Is hashset sorted in java?

1185


What are the restrictions that are applied to the java static methods?

985


What is anti pattern in programming?

968


What is a method type?

1005


What is static synchronization?

1103


What is the method overriding?

1082


Why is String immutable?

1062


What is the simpletimezone class in java programming?

1131


What is the epoch date?

1023


What is the difference between the size and capacity of a vector?

1041


How many bytes is a string java?

1023


What is class array in java?

1054


Write the algorithm to check the number non-leaf nodes in a tree.

1076


Explain jvm, jre, and jdk?

1017