how to fing linkedlist is circular or not?



how to fing linkedlist is circular or not?..

Answer / 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

More Core Java Interview Questions

What is type casting?

2 Answers  


What is the access scope of a protected method?

0 Answers  


Can we override the main method?

4 Answers  


Can a final variable be null?

0 Answers  


What class of exceptions are generated by the java run-time system?

0 Answers  






What are the two types of exceptions in java? Which are the differences between them?

0 Answers  


What class is used to implement a Throwable array?

3 Answers  


what is bytecode ?explain in detail and watz the difference between bytecode and machine code?

6 Answers   Lucent,


What is a ternary operator in java?

0 Answers  


What's the purpose of using break in each case of switch statement?

0 Answers  


Is minecraft java edition free?

0 Answers  


What methodology can be utilized to link to a database?

0 Answers  


Categories