Question: C program required You are asked to write a program to detect whether a list contains a cycle or not. Your program should read the

C program required

C program required You are asked to write a program to detect

You are asked to write a program to detect whether a list contains a cycle or not. Your program should read the input from the file, and output the answer to another file. The first argument is the input file name, while the second argument is the output file name. Name your program as lab1-94.c. Input file: There are at most 100 lines. Each line contains two numbers (nm), meaning that the next of node n is node m. You can assume that the input must form a list with either 0 or 1 cycle. You can also assume that the list head must be node 1, and node 1 may not be the first line of input. Output file: If the list contains a cycle, output Yes n, where n is the size of the cycle. If the list does not contain a cycle, output No n, where n is the number of nodes in the list. Sample Input: 1 2 2 3 3 4 4 5 Sample Output: No 5

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!