Add BFS tree

This commit is contained in:
stefiosif
2022-06-11 19:27:03 +03:00
parent dfa8e649ee
commit b5b031db7f
4 changed files with 138 additions and 19 deletions

View File

@@ -23,6 +23,13 @@ public:
// Reverse graph directions
Graph<T> reverse();
// Number of vertices
std::uint16_t V();
// Number of edges
// TODO: Calculate bidirectional edges once
std::uint16_t E();
// Adjacency matrix representation
std::set<T> vertices;
std::map<T, std::set<T>> adjMatrix;
@@ -45,6 +52,20 @@ Graph<T> Graph<T>::reverse() {
return Graph<T>();
}
template<typename T>
std::uint16_t Graph<T>::V() {
return vertices.size();
}
template<typename T>
std::uint16_t Graph<T>::E() {
std::uint16_t edges = 0;
for (const auto& v : vertices) {
edges += adjMatrix[v].size();
}
return edges;
}
} // namespace graph
#endif