Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

2nd Edition

0471180742, 978-0471180746

More Books

Students also viewed these Databases questions

Question

Who should apply a scorecard approach?

Answered: 1 week ago

Question

7. List behaviors to improve effective leadership in meetings

Answered: 1 week ago

Question

6. Explain the six-step group decision process

Answered: 1 week ago