chi
03/18/2018, 8:41 PMfun deleteNode(root: BinaryTreeNode<T>?, value: T): BinaryTreeNode<T>? {
var troot: BinaryTreeNode<T>? = root ?: return null
if (troot!!.data > value) {
troot.leftChild = deleteNode(troot.leftChild, value)
} else if (troot.data < value) {
troot.rightChild = deleteNode(troot.rightChild, value)
} else {
if (troot.leftChild != null && troot.rightChild != null) {
val temp = root
val minNodeForRight = temp.rightChild?.getMinimum()
troot.data = minNodeForRight?.data!!
deleteNode(troot.rightChild, minNodeForRight.data)
} else if (troot.leftChild != null) {
troot = troot.leftChild
} else if (troot.rightChild != null) {
troot = troot.rightChild
} else
troot = null
}
return troot
}