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 are the 5 types of organizational structures?
How can I check whether a file exists? I want to warn the user if a requested input file is missing.
What is a floating point in c?
Why structure is used in c?
How can I delete a file?
praagnovation
An instruction which is analysed and acted upon by the processor prior to the compiler going its work a) directive b) constructive c) constant d) absolute mode
Does sprintf put null character?
Explain which function in c can be used to append a string to another string?
In C programming, what command or code can be used to determine if a number of odd or even?
What is the use of header files?
What is use of null pointer in c?
What is indirection? How many levels of pointers can you have?
What is Dynamic memory allocation in C? Name the dynamic allocation functions.
1) There is a singing competition for children going to be conducted at a local club. Parents have been asked to arrive at least an hour before and register their children’s names with the Program Manager. Whenever a participant registers, the Program Manager has to position the name of the person in a list in alphabet order. Write a program to help the Program Manager do this by placing the name in the right place each time the Program Manger enters a name. The Logic should be written in Data Structures?