From 4bb1d6a36c7bc467273744d16e5cbca6c6c0c1c6 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Thu, 31 Mar 2022 22:08:42 +0200 Subject: [PATCH] AB3: Fix toString() --- src/BodyForceTreeMap.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/BodyForceTreeMap.java b/src/BodyForceTreeMap.java index 752861f..1d250bc 100644 --- a/src/BodyForceTreeMap.java +++ b/src/BodyForceTreeMap.java @@ -86,13 +86,14 @@ public class BodyForceTreeMap { return this.size; } - private String toString(BodyForceTreeMapItem item, String indent) { + private String toString(BodyForceTreeMapItem item) { + String s = ""; if (item == null) { - return ""; + return s; } - String s = String.format("%s{%s: %s}\n", indent, item.key(), item.value()); - s += this.toString(item.left(), indent + "| "); - s += this.toString(item.right(), indent + "| "); + s += this.toString(item.right()); + s += String.format("{%s: %s}\n", item.key(), item.value()); + s += this.toString(item.left()); return s; } @@ -101,6 +102,6 @@ public class BodyForceTreeMap { * descending according to the mass of the bodies. */ public String toString() { - return toString(root, ""); + return toString(root); } }