Question: How can I read the two files and how will the entry be terminated with '#'? I don't know what I'm tried for at this

How can I read the two files and how will the entry be terminated with '#'? I don't know what I'm tried for at this point. C++ only.

Can you help me with GetGraph?

Retrieves a graph from a special file and sets up the adjacency list for the graph. 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.

In short, This function has to read a file and store them in an undirected graph or directed graph. It has to represent an adjacency array of the graph for both types.

//*********************************************************** // Function Name: GetGraph // Purpose: get a file that has a graph representing as adjacency list // Functions Called: AddVertex, AddUniEdge, AddBiDirEdge //************************************************************ template void Graph::GetGraph() { edgeRep G1; vertex dist; ifstream input, input2; string line; input.open("graphs2.txt"); while (!input.eof()) { input >> line; AddVertex(dist.name); while (input >> line != '#') { input >> line; AddUniEdge(G1.name, G1.weight); } } input.close(); input2.open("graph3.txt"); while (!input.eof()) { input >> line; AddVertex(dist.name); while (input >> line != '#') { input >> line; AddBiDirEdge(dist.name, G1.name, G1.weight); } } input2.close(); }

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 int Graph::AddBiDirEdge(V& v1, V& v2, W& wt) { for (int i = 0; i < MAX; i++) { if (G[i] == NULL) { G[i] = v2; G[i + 1] = v1, wt; return 1; } } return 0; }

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