Make bfs return a digraph since shortest-path in-out trees are directed graphs
This commit is contained in:
@@ -12,16 +12,16 @@ namespace algo {
|
||||
template<typename T>
|
||||
class BFS {
|
||||
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();
|
||||
private:
|
||||
Digraph<T> G;
|
||||
T root;
|
||||
Graph<T> G;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
@@ -34,7 +34,7 @@ std::map<T, bool> BFS<T>::initExplore() {
|
||||
}
|
||||
|
||||
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, bool> graphExplore = initExplore();
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user