Skip to content

Commit

Permalink
Improve TreeNode and Support
Browse files Browse the repository at this point in the history
  • Loading branch information
bky373 committed Jun 26, 2024
1 parent 8d10db2 commit 4ffc561
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/main/java/org/example/TreeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ public String toString() {
return "TreeNode[" + val + "]";
}

public String toDetailString() {
return "TreeNode[v=" + val + ", l=" + left + ", r=" + right +"]";
public String toStringWithLR() {
return """
TreeNode{v=%s, l=%s, r=%s}""".formatted(val,
left != null ? left.toStringWithLR() : null,
right != null ? right.toStringWithLR() : null);
}
}
15 changes: 14 additions & 1 deletion src/test/java/support/TreeNodeSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@ public class TreeNodeSupport {
public static final TreeNode NODE_9 = new TreeNode(9);
public static final TreeNode NODE_10 = new TreeNode(10);

public static TreeNode linkLeftRight(TreeNode node, TreeNode left, TreeNode right) {
public static TreeNode linkLeftAndRight(int parent, int left, int right) {
TreeNode node = new TreeNode(parent);
node.left = new TreeNode(left);
node.right = new TreeNode(right);
return node;
}

public static TreeNode linkLeftAndRight(TreeNode parent, int left, int right) {
parent.left = new TreeNode(left);
parent.right = new TreeNode(right);
return parent;
}

public static TreeNode linkLeftAndRight(TreeNode node, TreeNode left, TreeNode right) {
node.left = left;
node.right = right;
return node;
Expand Down

0 comments on commit 4ffc561

Please sign in to comment.