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
Is c compiled or interpreted?
What are control structures? What are the different types?
Is it possible to initialize a variable at the time it was declared?
Explain what are compound statements?
What is the function of this pointer?
#include show(int t,va_list ptr1) { int a,x,i; a=va_arg(ptr1,int) printf(" %d",a) } display(char) { int x; listptr; va_star(otr,s); n=va_arg(ptr,int); show(x,ptr); } main() { display("hello",4,12,13,14,44); }
Q.1 write aprogram to stack using linklist o insert 40 items? Q.2 write a program to implement circular queue with help of linklist?
What is character constants?
How to delete a node from linked list w/o using collectons?
what is the role you expect in software industry?
Write a program to display all the prime nos from 1 to 1000000, your code should not take time more than a minute to display all the nos.
Explain void pointer?
Does * p ++ increment p or what it points to?
explain what are actual arguments?
What is fflush() function?