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 |
What is a method type?
What is the difference between Checked and Unchecked exception? Give some examples
What is collection class in java?
How do you get length in java?
What modifiers may be used with a top-level class?
Can we have any code between try and finally blocks?
what is the difference between abstract class and Interface?where we can use it in realtime projects?
23 Answers Agile Software, Cognizant, IBM, Innodata, Logica CMG, Mitosis, Nagarro, Value Chain,
Differentiate between overriding and overloading cases?
When do I need to use reflection feature in java?
Is an array a vector?
what is the use of reference variable
What restrictions are placed on method overriding in java programming?