From 75c6a0579f431d64e272037c8c245e0e4fe41fe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Thu, 25 May 2023 23:24:34 +0200 Subject: [PATCH] fixed findProperties and a improvement --- src/Graph.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Graph.java b/src/Graph.java index 21ff84a..fef94a6 100644 --- a/src/Graph.java +++ b/src/Graph.java @@ -95,11 +95,19 @@ public class Graph { exzentrizität = distanzMatrix.getValueAt(columnIndex, rowIndex); } } + if(exzentrizität == 0) { + connected = false; + return; + } exzentrizitäten.add(exzentrizität); } } public void calculateProperties() { + if(!connected) { + return; + } + radius = Integer.MAX_VALUE; diameter = -1; connected = true; @@ -108,20 +116,16 @@ public class Graph { for(int rowIndex = 0; rowIndex < exzentrizitäten.size(); rowIndex++) { if(exzentrizitäten.get(rowIndex) > diameter) { diameter = exzentrizitäten.get(rowIndex); - centre.clear(); + } + if(exzentrizitäten.get(rowIndex) == radius) { centre.add(rowIndex + 1); } if(exzentrizitäten.get(rowIndex) < radius) { radius = exzentrizitäten.get(rowIndex); - } - if(exzentrizitäten.get(rowIndex) == diameter) { + centre.clear(); centre.add(rowIndex + 1); } } - - if(radius == 0) { - connected = false; - } } public void findComponents() {