#include #include #include #include #include using namespace std; //A graph where each node is a string class Graph{ public: Graph(){ directed=true; } //Create a graph object with the given nodes //and initialize the adjacent lists to empty Graph (string nodeArray[], int len, bool d); //Precondition: from and to nodes are in the vector of nodes void AddEdge (const string & from, const string & to); //return the adjacent list of node u list AdjacentNodes (const string & u); int FindNode (const string & u); void Display(); //Explore and visit all vertices of the graph that are //reachable from node s in BFS order // When finish: Display // * the depth of all reachable vertices (i.e., shortest distance to s) // * the predecessors of all reachable vertices (BFS tree) void BFS_Explore (string s); private: bool directed; //true: directed graph, false: undirected graph vector nodes; //edges[i] stores all nodes that nodes[i] is connected to // //for undirected graph, we store each edge twice, for example, // if node a and b are connected by an edge, // b is in the adjacent list of a, and a is in the adjacent list of b vector> edges; };