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
Explain the advantages of using macro in c language?
What is a void pointer in c?
Explain is it better to bitshift a value than to multiply by 2?
What is anagram in c?
Explain pointers in c programming?
What is pointer to pointer in c language?
What are the types of data types and explain?
What is the data segment that is followed by c?
What is the difference between exit() and _exit() function?
Is c object oriented?
Explain what is the benefit of using const for declaring constants?
What does calloc stand for?
How old is c programming language?
What is the use of volatile?
What is s in c?