Skip to content

Commit 8cbc15a

Browse files
committed
Tree Updates
Tree Updates
1 parent 214ad00 commit 8cbc15a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed
Binary file not shown.

src/chapter6trees/FillNextSiblingsWithRecursion.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,16 @@
1515
package chapter6trees;
1616

1717
public class FillNextSiblingsWithRecursion {
18-
18+
public static void fillNextSiblings(SiblingBinaryTreeNode root) {
19+
if (root == null)
20+
return;
21+
if (root.getLeft() != null)
22+
root.getLeft().setNextSibling(root.getRight());
23+
if (root.getRight() != null)
24+
if(root.getNextSibling() != null)
25+
root.getRight().setNextSibling(root.getNextSibling().getLeft());
26+
else root.getRight().setNextSibling(null);
27+
fillNextSiblings(root.getLeft());
28+
fillNextSiblings(root.getRight());
29+
}
1930
}

0 commit comments

Comments
 (0)