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
When would you use a pointer to a function?
What is c system32 taskhostw exe?
Explain what are its uses in c programming?
Why do we use & in c?
What are the 5 elements of structure?
What is use of bit field?
write a program for the normal snake games find in most of the mobiles.
Why is main function so important?
What is a example of a variable?
What is build process in c?
What is a pointer in c?
What is getch () for?
write a program to create a sparse matrix using dynamic memory allocation.
Describe the difference between = and == symbols in c programming?
Why clrscr is used in c?