Make bfs return a digraph since shortest-path in-out trees are directed graphs

This commit is contained in:
stefiosif
2022-06-12 20:32:15 +03:00
parent 2029900035
commit 4058c3f6fb

View File

@@ -12,16 +12,16 @@ namespace algo {
template<typename T> template<typename T>
class BFS { class BFS {
public: public:
BFS(Digraph<T> G, T root) : G(G), root(root) {} BFS(Graph<T> G) : G(G) {}
// //
std::map<T, std::set<T>> run(); Digraph<T> run(const T& root);
// // Initialize the lookup table that is used to
// show which vertices have been traversed
std::map<T, bool> initExplore(); std::map<T, bool> initExplore();
private: private:
Digraph<T> G; Graph<T> G;
T root;
}; };
template<typename T> template<typename T>
@@ -34,7 +34,7 @@ std::map<T, bool> BFS<T>::initExplore() {
} }
template<typename T> template<typename T>
std::map<T, std::set<T>> BFS<T>::run() { Digraph<T> BFS<T>::run(const T& root) {
std::map<T, std::set<T>> tree; std::map<T, std::set<T>> tree;
std::map<T, bool> graphExplore = initExplore(); std::map<T, bool> graphExplore = initExplore();
std::queue<T> Q; std::queue<T> Q;
@@ -54,7 +54,7 @@ std::map<T, std::set<T>> BFS<T>::run() {
} }
} }
return tree; return Digraph<T>(tree);
} }
} // namespace algo } // namespace algo