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 Depth-First 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 input1.txt contains:
4
01
02
12
23
This corresponds to a graph with 4 vertices, where the edges connect vertices 0 and 1,0 and 2,1 and 2, and so on.
The adjacency matrix is:
-11-
1-1-
11-1
--1-
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 input1.txt, and starting from 0, the traversal should be:
DFS starting from 0:
0231 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 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 Accounting Questions!