Question: Write a C++ program called ts.cpp that implements the topological sorting algorithm based on the DFS algorithm. Your program should read an input file name

 Write a C++ program called ts.cpp that implements the topological sortingalgorithm based on the DFS algorithm. Your program should read an input

Write a C++ program called ts.cpp that implements the topological sorting algorithm based on the DFS algorithm. Your program should read an input file name and determine if the input graph is a DAG ( directed acyclic graph) or not. If the graph is not a DAG, your program has to stop without further processing. However, if it's a DAG, your program should display the starting node(s), popping-off order, and topologically sorted list. In the problem, you can assume that the number of nodes in the input file is less than 100 Input file format: This is a sample input file called tl.txt. 2 The first line (3 in the example) indicates that there are three vertices in the graph. The second line (2 in the example) presents the number of edges in the graph. The remaining two lines are the edge information in the graph. For the homework, you should assume that the first vertex starts from the number 0. Thus, tl.txt describes a directed graph like below: This is a sample run of the program on the cloud9. Y our program should be compiled and executed exactly like this $ gtt -o ts ts.cpp Enter a filename: C:\\tmp\\tl.txt This is a DAG Start node (s): 0 Popping-off order: 2 1 0 Topological sort: 0 ->1 -> 2

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!