Answer Posted / jaroosh
The above method is working of course, but is not the most
efficient. Other methods are however quite complex and not
so easy to explain.
Anyway, to exemplify this aforementioned method, maybe not
the most efficient code, but off the top of my head, hope
there are no misspellings.
bool isCyclic(LinkedNode *list)
{
if(list == NULL || list->next == NULL) return false;
LinkedNode *node1 = list, *node2 = node1->next;
while(node1 != node2)
{
if(node1==NULL || node2==NULL || node2->next == NULL)
return false;
node1 = node1->next;
node2= node2->next->next;
}
return true;
}
NOTE: the assumption is that for noncyclic list, the last
node has next pointer set to NULL.
| Is This Answer Correct ? | 6 Yes | 7 No |
Post New Answer View All Answers
Write a program to print fibonacci series using recursion?
What is main () in c language?
How many keywords (reserve words) are in c?
What is the use of a semicolon (;) at the end of every program statement?
What is ponter?
How does sizeof know array size?
What is difference between constant pointer and constant variable?
Explain about block scope in c?
Is main a keyword in c?
Difference between Shallow copy and Deep copy?
Is c programming hard?
Why is c so important?
What does nil mean in c?
what is bit rate & baud rate? plz give wave forms
Do you have any idea how to compare array with pointer in c?