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
What is string syntax?
Is passing by reference faster?
How does a for loop work java?
how to know the total memory occupied by the objects in the ArrayList(Array list may contain duplicate objects)
What are the types of methods in java?
What are keywords in programming?
What does nextint () do in java?
What is a singleton puppy?
What is the program development process?
What is data string?
What is the difference between the final method and abstract method?
Can we override private constructor in java?
What is the final method?
How to use string tokenizer class.
What access modifiers can be used for methods?