Hi! I am working the assignment below for my Data Structures class and I am getting this error: [Error] expected primary-expression before ')' token. I have commented the line where I am getting the error, as well as provided the contents for the .dat file I am using. Thanks for the help!
Assignment:
Write an interactive program reads the name of cities and distances between them and provides the following functionality:
Given a city, print a list of all of the neighboring cities
Print a list of all cities and their neigbors
Given a city delete the city from the graph
Given a city, find the closest city
.dat file contents:
Norfolk 4 Chesapeake 10 VirginiaBeach 5 Portsmouth 2 Hampton 20
Suffolk 4 Chesapeake 20 Portsmouth 5 NewportNews 30 Windsor 10
Portsmouth 3 Chesapeake 10 Norfolk 2 Suffolk 5
Hampton 2 NewportNews 5 Norfolk 20
VirginiaBeach 2 Norfolk 5 Chesapeake 10
Chesapeake 5 NewportNews 10 Suffolk 20 Portsmouth 10 VirginiaBeach 10 Moyock 20
Williamsburg 1 NewportNews 10
Moyock 1 Chesapeake 20
Windsor 1 Suffolk 10
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#include<iostream>
#include<list>
#include<fstream>
#include<string>
using namespace std;
typedef list<string> adj_list;
typedef adj_list :: iterator adj_it;
struct node
{
string vertex;
adj_list adj;
};
struct neighbors
{
string city;
int distance;
};
typedef list<node> graph;
typedef graph :: iterator g_it;
//build the graph
void build_graph(graph & G)
{
//cout <<"Entering build_graph "<<endl;
ifstream infile;
infile.open("prog4graph.dat");
node temp;
int num_adj_nodes;
string adj_vertex;
neighbors neighbor;
while (!infile.eof())
{
infile >>temp.vertex;
// cout << temp.vertex <<endl;
infile >> num_adj_nodes;
//cout <<"number of nodes = "<<num_adj_nodes <<endl;
temp.adj.clear();
for(int i = 0; i < num_adj_nodes; i++)
{
infile >> adj_vertex;
infile >> neighbor.city;
infile >> neighbor.distance;
temp.adj.push_back(neighbors); // Error here
}
G.push_back(temp);
}
//cout << "Leaving build_graph"<<endl;
}
//print the graph
void print_graph(graph G)
{
for(g_it it = G.begin(); it != G.end();it++)
{
cout << it->vertex<<":";
for(adj_it it1 = it->adj.begin(); it1 != it->adj.end(); it1++)
{
cout << *it1;
}
cout <<endl;
}
}
int main()
{
graph G;
build_graph(G);
print_graph(G);
system("pause");
return 0;
}
|