Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started