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 sizeof () operator?
Does java linked list allow duplicates?
These static constructors are correct ? class A { statc intA() { } static A(int x,int y) { } static A(int x) { } }
What is toarray method in java?
What is %02d?
hr interview how many minutes asking question
What is the difference between instanceof and isinstance?
hi am an engineering student and my next plan is for ms in either in us or australia i got my passport but i dont know anything bout visa can u give brief idea 1)How to get prepared for visa and 2)How to apply for top universities and 3)How to pay the fee and so on These all are basic questions plz give me a clear idea
How do you add an element to an arraylist in java?
What are static variables and functions?
Which object oriented concept is achieved by using overloading and overriding?
What is a substitution variable?
Describe 2 different ways to concatenate two strings.
Do we need to manually write Copy Constructor?
How to make a write-only class in java?