#pragma once #include #include #include #include #include #include using namespace std; class directedGraph { private: class vertex { public: string data; //or whatever vector neighbors; vertex(string s) { data = s; } }; unordered_map vertexMap; public: //run time: a.c. O(1), w.c. O(n) void addVertex(string s) { vertexMap[s] = new vertex(s); } //add an edge going from a to b. //Run time: a.c. O(1), w.c. O(n) void addDirectedEdge(string a, string b) { vertex* aVert = vertexMap.at(a); vertex* bVert = vertexMap.at(b); aVert->neighbors.push_back(bVert); } //add a bidirectional edge between a and b void addBasicEdge(string a, string b) { addDirectedEdge(a, b); addDirectedEdge(b, a); } void testDisplay() { for (auto x : vertexMap) { cout << x.first << ": "; vertex* xVert = x.second; for (int i = 0; i < xVert->neighbors.size(); i++) cout << xVert->neighbors[i]->data << ", "; cout << endl; } } };