Add BFS tree
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user