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
What is the -> in c?
Is it cc or c in a letter?
What are preprocessor directives in c?
How many types of arrays are there in c?
Can you assign a different address to an array tag?
How can I write a function analogous to scanf?
What are different types of operators?
What are dangling pointers in c?
what are the advantages of a macro over a function?
Are bit fields portable?
How many levels deep can include files be nested?
What is a structure member in c?
What is extern keyword in c?
Does sprintf put null character?
Using which language Test cases are added in .ptu file of RTRT unit testing???