From 780a537e50803c03c227ab36fede80979ef5a94e Mon Sep 17 00:00:00 2001 From: iridiumR Date: Fri, 10 Dec 2021 09:29:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9E=83=E5=9C=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ex11/graph.hpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/ex11/graph.hpp b/ex11/graph.hpp index 43afa3b..cc01451 100644 --- a/ex11/graph.hpp +++ b/ex11/graph.hpp @@ -157,7 +157,7 @@ public: virtual void display() { - std::cout << std::left << std::setw(5) << " "; + std::cout << std::left << std::setw(14) << " "; for (int i = 0; i < V._len; i++) if (V[i] != NULL) std::cout << std::setw(4) << i << std::setw(10) << V[i]->data; @@ -166,14 +166,16 @@ public: if (V[i] != NULL) { std::cout << std::setw(4) << i << std::setw(10) << V[i]->data; - for (int j = 0; j < E[i]._len;j++) - if(E[i][j]==NULL) - std::cout << std::setw(14) << "-"; - else - std::cout<< std::setw(14) << E[i][j]->weight; + for (int j = 0; j < V._len; j++) + if (V[j] != NULL) + { + if (E[i][j] == NULL) + std::cout << std::setw(14) << "-"; + else + std::cout << std::setw(14) << E[i][j]->weight; + } printf("\n"); } - } };