From 9fa159b94ee7db2825a0704cba5d2cf4627cc828 Mon Sep 17 00:00:00 2001 From: Guilherme Werner Date: Sun, 18 Jun 2023 14:33:12 -0300 Subject: [PATCH] Update debugs --- Source/Graph.cpp | 18 ++++++------------ Source/Graph.h | 37 ++++++++++++++++++++----------------- Source/Main.cpp | 3 +++ 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Source/Graph.cpp b/Source/Graph.cpp index 4ee61e0..9a666c0 100644 --- a/Source/Graph.cpp +++ b/Source/Graph.cpp @@ -2,19 +2,8 @@ void Graph::PrintIncidenceMatrix() { - cout << " "; - - for (int j = 0; j < edges; j++) - { - cout << j << " "; - } - - cout << endl; - for (int i = 0; i < nodes; i++) { - cout << i << " "; - for (int j = 0; j < edges; j++) { int val = this->matrix[i][j]; @@ -35,6 +24,11 @@ void Graph::PrintIncidenceMatrix() cout << endl; } +void Graph::PrintAdjacencyMatrix() +{ + Graph::_PrintAdjacencyMatrix(this->GetAdjacencyMatrix()); +} + void Graph::AddEdge(int u, int v) { this->matrix[u][this->edges] = 1; @@ -117,7 +111,7 @@ Graph *Graph::ToTransitiveClosure() } cout << "TC:" << endl; - Graph::PrintAdjacencyMatrix(closure); + Graph::_PrintAdjacencyMatrix(closure); return new Graph(closure, closure.size()); } diff --git a/Source/Graph.h b/Source/Graph.h index 158f6eb..8fd5c6a 100644 --- a/Source/Graph.h +++ b/Source/Graph.h @@ -77,6 +77,8 @@ public: public: void PrintIncidenceMatrix(); + void PrintAdjacencyMatrix(); + void AddEdge(int u, int v); vector> GetAdjacencyMatrix(); @@ -86,23 +88,6 @@ public: Graph *ToTransitiveClosure(); public: - static void PrintAdjacencyMatrix(const vector> &adjacency) - { - int nodes = adjacency.size(); - - for (int i = 0; i < nodes; i++) - { - for (int j = 0; j < nodes; j++) - { - cout << adjacency[i][j] << " "; - } - - cout << endl; - } - - cout << endl; - } - static vector> MultiplyIncidenceMatrix(const vector> &left, const vector> &right) { int rows1 = left.size(); @@ -130,4 +115,22 @@ public: return result; } + +private: + void _PrintAdjacencyMatrix(const vector> &adjacency) + { + int nodes = adjacency.size(); + + for (int i = 0; i < nodes; i++) + { + for (int j = 0; j < nodes; j++) + { + cout << adjacency[i][j] << " "; + } + + cout << endl; + } + + cout << endl; + } }; diff --git a/Source/Main.cpp b/Source/Main.cpp index aa74acc..3553bc1 100644 --- a/Source/Main.cpp +++ b/Source/Main.cpp @@ -11,17 +11,20 @@ int main() cout << "M1:" << endl; g1->PrintIncidenceMatrix(); + g1->PrintAdjacencyMatrix(); auto m1 = g1->GetIncidenceMatrix(); Graph *g2 = g1->ToTransitiveClosure(); cout << "M2:" << endl; g2->PrintIncidenceMatrix(); + g2->PrintAdjacencyMatrix(); auto m2 = g2->GetIncidenceMatrix(); auto m3 = Graph::MultiplyIncidenceMatrix(m1, m2); Graph *g3 = new Graph(m3); cout << "M3:" << endl; g3->PrintIncidenceMatrix(); + g3->PrintAdjacencyMatrix(); return 0; }