40 lines
866 B
C++
40 lines
866 B
C++
#ifndef BREADTH_FIRST_TREE_H_
|
|
#define BREADTH_FIRST_TREE_H_
|
|
|
|
#include "digraph.h"
|
|
|
|
namespace graph {
|
|
|
|
template <typename T> class BreadthFirstTree : public Digraph<T> {
|
|
public:
|
|
BreadthFirstTree() = default;
|
|
|
|
BreadthFirstTree(std::unordered_map<T, std::unordered_set<T>> G, T root)
|
|
: BreadthFirstTree<T>(Digraph<T>(G), root) {}
|
|
|
|
BreadthFirstTree(Digraph<T> G, T root);
|
|
|
|
void removeEdgeTo(const T &u);
|
|
|
|
T root{};
|
|
};
|
|
|
|
template <typename T>
|
|
BreadthFirstTree<T>::BreadthFirstTree(Digraph<T> G, T root) {
|
|
this->adjList = algo::BreadthFirstSearch<T>(G.adjList).execute(root);
|
|
}
|
|
|
|
template <typename T> void BreadthFirstTree<T>::removeEdgeTo(const T &u) {
|
|
for (const auto &x : this->vertices()) {
|
|
for (const auto &y : this->adjList[x]) {
|
|
if (y == u) {
|
|
this->remove(x, u);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace graph
|
|
|
|
#endif |