org.psjava.ds.tree.binary.BinaryTreeToString Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of psjava Show documentation
Show all versions of psjava Show documentation
Problem Solving Library for Java
The newest version!
package org.psjava.ds.tree.binary;
public class BinaryTreeToString {
public static String toString(BinaryTreeNodeWithParent rootOrNull) {
if (rootOrNull == null)
return "Empty";
else
return toStringRecursively(rootOrNull);
}
private static String toStringRecursively(BinaryTreeNodeWithParent root) {
String r = root.getData().toString();
if (root.hasLeft() || root.hasRight()) {
r += "(";
if (root.hasLeft())
r += toStringRecursively(root.getLeft());
r += ",";
if (root.hasRight())
r += toStringRecursively(root.getRight());
r += ")";
}
return r;
}
private BinaryTreeToString() {
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy