Add reverse a digraph function and test

This commit is contained in:
stefiosif
2022-06-13 17:04:43 +03:00
parent 1e16e671ea
commit de29435933
2 changed files with 46 additions and 1 deletions

View File

@@ -28,7 +28,15 @@ Digraph<T>::Digraph(std::map<T, std::set<T>> digraph) {
template<typename T>
Digraph<T> Digraph<T>::reverse() {
return Digraph<T>();
std::map<T, std::set<T>> revMatrix;
for (const auto& v : Graph<T>::adjMatrix) {
for (const auto& u : v.second) {
revMatrix[u].insert(v.first);
}
}
return revMatrix;
}
} // namespace graph