Question
Can you help me with GetGraph? C++ only. Retrieves a graph from a special file and sets up the adjacency list for the graph. I
Can you help me with GetGraph? C++ only.
Retrieves a graph from a special file and sets up the adjacency list for the graph. I am supplying 1 file. The program will be able to read any graph that is in the same format: graph node followed by any adjacent nodes followed by distance/weight to the node. The adjacency entry is terminated by #. I want to have both of the files to be in the function.
GetGraph //*********************************************************** // Function Name: GetGraph // Purpose: get a file that has a graph representing as adjacency list // Functions Called: AddVertex, AddUniEdge, AddBiDirEdge //************************************************************ template
This is a c++ only.
Graph2.txt (bidirected)
Atlanta Houston 650 Washington 600 # Austin Dallas 200 Houston 300 # Buffalo New_York 450 Newark 500 # Chicago Denver 550 New_York 950 # Dallas Austin 200 Chicago 1500 # Denver Atlanta 800 Chicago 550 # Houston Atlanta 650 # Newark Atlanta 1100 # New_York Chicago 950 Buffalo 450 # Washington Atlanta 600 Dallas 700 #
Graph3.txt (directed graph)
Atlanta Houston 650 Washington 600 # Austin Dallas 200 Houston 300 # Buffalo New_York 450 Newark 500 # Chicago Denver 550 New_York 950 # Dallas Austin 200 Chicago 1500 # Denver Atlanta 800 Chicago 550 # Houston Atlanta 650 # Newark Atlanta 1100 # New_York Chicago 950 Buffalo 450 # Washington Atlanta 600 Dallas 700 #
EdgeRep
template // V is the vertex class; W is edge weight class struct edgeRep { V name; // Vertex name W weight; // Edge weight };
AddUniEdge
template int Graph::AddUniEdge(V& v1, V& v2, W &wt) { for (int i = 0; i < MAX; i++) { if (G[i] == NULL) { G[i] = v1; G[i + 1] = v2, wt; return 1; } } return 0; }
AddBiDirEdge
template
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