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 type casting?
What is the access scope of a protected method?
Can we override the main method?
Can a final variable be null?
What class of exceptions are generated by the java run-time system?
What are the two types of exceptions in java? Which are the differences between them?
What class is used to implement a Throwable array?
what is bytecode ?explain in detail and watz the difference between bytecode and machine code?
What is a ternary operator in java?
What's the purpose of using break in each case of switch statement?
Is minecraft java edition free?
What methodology can be utilized to link to a database?