Last active
November 13, 2020 14:57
-
-
Save brunofarache/6c1abfa81fb475c85ab5727b906ee856 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def connect(root: Node): Node = { | |
def connectEdges(left: Node, right: Node): Unit = { | |
if (left == null) return | |
println(left.value) | |
left.next = right | |
connectEdges(left.right, right.left) | |
} | |
def visit(node: Node): Unit = { | |
if (node == null || node.left == null) return | |
println(node.value) | |
node.left.next = node.right | |
connectEdges(node.left.right, node.right.left) | |
visit(node.left) | |
visit(node.right) | |
} | |
visit(root) | |
root | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment