Question: Complete the Graph class to allow it to store an adjacency matrix representation of the connections between vertices. It should then allow for a Depth
Complete the Graph class to allow it to store an adjacency matrix representation of the connections between vertices. It should then allow for a DepthFirst traversal through the graph.
In main, take as input a file name that corresponds to a file containing a 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 a pair of values that represent a single edge in the graph between two vertices. These edges are undirected and will always be between valid vertices.
Provide code to read in these edges and construct an adjacency matrix for this graph.
For example, the file inputtxt contains:
This corresponds to a graph with vertices, where the edges connect vertices and and and and so on
The adjacency matrix is:
Take as input an integer that represents the starting vertex and complete a DFS where you output each vertex visited. Because there are multiple possible DFS traversals, we will prefer the largest neighbors first. This means that we should push into the stack the lowest values first, and visit the largest vertices first. For inputtxt and starting from the traversal should be:
DFS starting from :
main.cpp: #include
#include
#include "Graph.h
int main
Add your code here
graph.h: no template provided graph.cpp: no template provided
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
