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 dynamic variable in c?
What is the difference between struct and typedef struct in c?
What is the difference between int main and void main?
What will be your course of action for a push operation?
Why functions are used in c?
Do array subscripts always start with zero?
write a program to reverse a every alternetive words in a string in a place. EX: Input is "this is the line of text" Output should be "shit is eht line fo text" Please any one tell me code for that.
Explain logical errors? Compare with syntax errors.
Explain what is a stream?
Explain the term printf() and scanf() used in c language?
how can use subset in c program and give more example
Explain what are run-time errors?
Which is the best website to learn c programming?
What is the size of array float a(10)?
When should a type cast not be used?