I’m making a binary tree with the help of a blog, first I’m making a node class but what’s happening inside there is mysterious to me…
data class TreeNode(var leftTreeNode: TreeNode? = null,
var rightTreeNode: TreeNode? = null,
val nodeData: T){
fun link(leftTreeNode: TreeNode<T>?, rightTreeNode: TreeNode<T>?)=this.apply{
linkLeft(leftTreeNode!!).linkRight(rightTreeNode!!)
}
private fun linkLeft(left: TreeNode<T>) = this.apply { leftTreeNode = left }
private fun linkRight(right: TreeNode<T>) = this.apply { rightTreeNode = right }
fun depth(value: Int) = this.apply { depth = value }
}
first, can we link two objects using a dot linkLeft(leftTreeNode!!).linkRight(rightTreeNode!!)
exactly what this dot( .
) is doing here
And then this depth function why it is assigning value
to the
depth
I know about depth is the number of edges from the root to a specific node.
Thanks in advance