Question: Topological Sorting provides the critical path through a graph and can identify if a graph contains a cycle. It does so by selecting the next

Topological Sorting provides the critical path through a graph and can identify if a graph contains a cycle. It does so by selecting the next vertex without incident edges.
Modify your existing Graph code to include Topological Sorting. In particular, always select the vertices in increasing order, for ties.
Add code to the main.cpp to accept as input, the name of a file. Read from the file the number of vertices and the edges between vertices, including edge weights and construct an adjacency graph. The file will contain a positive integer on the first line that represents the number of vertices in the graph. Each of the subsequent lines will contain three values that represent a single edge in the graph; the from vertex, the to vertex, and the non-negative weight. These edges are directed and will always be between valid vertices.
Provide code to read in these edges and construct an Topological Sorting for this graph.
For example, the file input1.txt contains:
6
521
501
401
411
311
231
031
This leads to a Topological Sort:
Order: 450231
If no ordering exists, output the message:
No Ordering Exists!

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 Programming Questions!