Hi all, what would be a better way of implementing...
# codereview
c
Hi all, what would be a better way of implementing this method to delete a node from a binary search tree
Copy code
fun 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
  }