1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
//***********************************************************
// Function Name: add_Vertices
// Purpose: Adds vertices by reading files and storing in either directional or bidirectional graph.
// Parameters: string filename, vertex<V, W>& dist, edgeRep<V, W>& G1, bool bi
// Functions Called: AddVertex, AddUniEdge, AddBiDirEdge
//************************************************************
template<class V, class W>
void Graph<V,W>::AddVertices(string filename, vertex<V, W>& dist, edgeRep<V, W>& G1, bool bi)
{
ifstream input(filename);
string line;
while (!input.eof())
{
input >> line;
AddVertex(dist.name);
input >> line;
while (line != "#")
{
if (bi)
AddBiDirEdge(dist.name, G1.name, G1.weight);
else
AddUniEdge(G1.name, G1.weight);
}
}
}
//***********************************************************
// Function Name: GetGraph
// Purpose: get a file that has a graph representing as adjacency list
// Functions Called: AddVertices
//************************************************************
template<class V, class W>
void Graph<V, W>::GetGraph()
{
edgeRep<V, W> G1;
vertex<V, W> dist;
AddVertices("graph2.txt", dist, G1, false);
AddVertices("graph3.txt", dist, G1, true);
}
|