#include #include #include #include #include #include #include using namespace std; #include "StringGraph.h" //Create a graph object with the given nodes //and initialize the adjacent lists to empty Graph::Graph (string nodeArray[], int len, bool d) { for (int i=0;i adjacentList; edges.push_back (adjacentList); } directed = d; } //Precondition: from and to nodes are in the vector of nodes // void Graph::AddEdge (const string & from, const string & to) { int cnt=0; int fromIndex, toIndex; //Find from and to nodes in the nodes vector for (int i=0;i Graph::AdjacentNodes (const string & u) { for (int i=0;i::iterator it; if (directed) cout <<"Directed Graph:\n"; else cout <<"Undirected Graph:\n"; cout <<"Vertex: {"; for (int i=0;i"< d; //the depth/hop count of all nodes from s map pred; // pred[u] is the node that leads us to u map color; //color[u] will be White, Gray, Black queue Q; // initialize all nodes to white for (int i=0;i adjNodes = AdjacentNodes (u); for (int j:adjNodes){ string v=nodes[j]; if (color[v]==White) { color[v]=Gray; d[v]=d[u]+1; pred[v]=u; Q.push(v); } } color[u]=Black; } //Display color, depth, predecessor for (int i=0;i