Problem:

Binary Search Tree III

Write a program which performs the following operations to a binary search tree $T$ by adding delete operation to B: Binary Search Tree II.

  
insert  $k$: Insert a node containing $k$ as key into $T$.

  
find $k$: Report whether $T$ has a node containing $k$. 

  
delete $k$: Delete a node containing $k$.

  
print: Print the keys of the binary search tree by inorder tree walk and  preorder tree walk respectively.

The operation delete $k$ for deleting a given node $z$ containing key $k$ from $T$ can be implemented by an algorithm which considers the following cases:

 If $z$ has no children, we modify its parent $z.p$ to replace $z$ with NIL as its child (delete $z$).

 If $z$ has only a single child, we "splice out" $z$ by making a new link between its child and its parent.

 If $z$ has two children, we splice out $z$'s successor $y$ and replace $z$'s key with $y$'s key.

Input

   In the first line, the number of operations $m$ is given. In the following $m$ lines, operations represented by insert $k$, find $k$, delete $k$ or print are given.

Output

For each find $k$ operation, print "yes" if $T$ has a node containing $k$, "no" if not.

  In addition, for each print operation, print a list of keys obtained by inorder tree walk and preorder tree walk in a line respectively. Put a space character before each key

Constraints

   
The number of operations $\leq 500,000$

The number of print operations $\leq 10$.

  
$-2,000,000,000 \leq key \leq 2,000,000,000$

  
The height of the binary tree does not exceed 100 if you employ the above pseudo code.

The keys in the binary search tree are all different.

Sample Input 1

18
insert 8
insert 2
insert 3
insert 7
insert 22
insert 1
find 1
find 2
find 3
find 4
find 5
find 6
find 7
find 8
print
delete 3
delete 7
print

Sample Output 1

yes
yes
yes
no
no
no
yes
yes
 1 2 3 7 8 22
 8 2 1 3 7 22
 1 2 8 22
 8 2 1 22

Reference

Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press.



Sample input:
18
insert 8
insert 2
insert 3
insert 7
insert 22
insert 1
find 1
find 2
find 3
find 4
find 5
find 6
find 7
find 8
print
delete 3
delete 7
print


Sample output:
yes
yes
yes
no
no
no
yes
yes
 1 2 3 7 8 22
 8 2 1 3 7 22
 1 2 8 22
 8 2 1 22

Submission status: Accepted

Solution code:
class Node:
  def __init__(self, key):
    self.key = key
    self.right = None
    self.left = None

class BST:
  root = None
  def insert(self, key):
    x = self.root
    y = None
    z = Node(key)
    while x != None:
      y = x
      if(z.key < y.key):
        x = x.left
      elif(y.key < z.key):
        x = x.right
    
    if y is None:
      # 初回
      self.root = z
    else:
      # yがターゲットになっているので
      if z.key < y.key:
        y.left = z
      elif y.key < z.key:
        y.right = z
        
  def preorder(self, par):
    if par is not None:
      print(" {}".format(par.key), end="")
      self.preorder(par.left)
      self.preorder(par.right)
  
  def inorder(self, par):
    if par is not None:
      self.inorder(par.left)
      print(" {}".format(par.key), end="")
      self.inorder(par.right)
      
  def find(self, key):
    x = self.root
    y = None
    z = Node(key)
    flag = False
    while x is not None: 
      y = x
      if(z.key < y.key):
        x = x.left
      elif(y.key < z.key):
        x = x.right
      else:
        flag = True
        break
    return flag
  
  def delete(self, key):
    if self.find(key):
      x = self.root
      y = None

      while x is not None: 
        y = x
        if(key < y.key):
          x = x.left
        elif(y.key < key):
          x = x.right
        else:
          # rootが対象のノードの場合
          break
        if(x.key == key):
          break

      # yが親、子のxがdeleteの対象
      x_children  = [c for c in [x.left, x.right] if c is not None]
      if len(x_children) == 0:
        # 親から子の情報を削除
        for c in [y.left, y.right]:
          if c is not None and c.key == key:
            # yの左右どっちにcがあるのか同定してx_children[0]をぶちこむ
            which_side = [i for i, x in enumerate([y.left, y.right]) if x is not None and x.key == c.key][0]
            if which_side == 0:
              # 左側
              y.left = None
            else:
              # 右側
              y.right = None
      elif len(x_children) == 1:
        # 子の子を親の子にする（字面が妙な雰囲気）
        for c in [y.left, y.right]:
          if c is not None and c.key == key:
            # yの左右どっちにcがあるのか同定してx_children[0]をぶちこむ
            which_side = [i for i, x in enumerate([y.left, y.right]) if x is not None and x.key == c.key][0]
            if which_side == 0:
              # 左側
              y.left = x_children[0]
            else:
              # 右側
              y.right = x_children[0]
      else:
        # print("ふたこぶ")
        # print("key: {}".format(key))
        # 削除予定の子から左側のうち最大のものをとってきて、削除予定のやつを削除したのちそこに入れる
        # とやったらなぜか右側の最小値で出すのが想定される解らしい どっちでもあってんだろが
        min_child = x.right
        # 一つ上の親を保持
        par = x
        while True:
          if min_child.left is None:
            break
          par = min_child
          min_child = min_child.left

        # print("min_childの親が知りたい {}".format(par.key))
        if(par.key == key):
          # 初っ端で終了した（下る世代の数が1）
          pass
        else:
          par.left = None
          min_child.right = x.right
          
        # 大本の削除対象のxの親であるyの左右どちらがxであるか同定し更新
        x_side = [i for i, s in enumerate([y.left, y.right]) if s is not None and s.key == x.key][0]
        # それを直接min_childとする
        if x_side == 0:
          # 左
          y.left = min_child
        else:
          # 右
          y.right = min_child
          
        min_child.left = x.left
        # print("---------------------------")
      
n = int(input())
bst = BST()
for _ in range(n):
  query = input().split()
  if query[0] == "insert":
    bst.insert(int(query[1]))
  elif query[0] == "find":
    print("yes" if bst.find(int(query[1])) else "no")
  elif query[0] == "print":
    # 中間巡回順, 先行巡回順
    root = bst.root
    bst.inorder(root)
    print()
    bst.preorder(root)
    print()
  elif query[0] == "delete":
    bst.delete(int(query[1]))

Submission status: Accepted

Solution code:
class Node:
  def __init__(self, key):
    self.key = key
    self.right = None
    self.left = None

class BST:
  root = None
  def insert(self, key):
    x = self.root
    y = None
    z = Node(key)
    while x != None:
      y = x
      if(z.key < y.key):
        x = x.left
      elif(y.key < z.key):
        x = x.right
    
    if y is None:
      # 初回
      self.root = z
    else:
      # yがターゲットになっているので
      if z.key < y.key:
        y.left = z
      elif y.key < z.key:
        y.right = z
        
  def preorder(self, par):
    if par is not None:
      print(" {}".format(par.key), end="")
      self.preorder(par.left)
      self.preorder(par.right)
  
  def inorder(self, par):
    if par is not None:
      self.inorder(par.left)
      print(" {}".format(par.key), end="")
      self.inorder(par.right)
      
  def find(self, key):
    x = self.root
    y = None
    z = Node(key)
    flag = False
    while x is not None: 
      y = x
      if(z.key < y.key):
        x = x.left
      elif(y.key < z.key):
        x = x.right
      else:
        flag = True
        break
    return flag
  
  def delete(self, key):
    if self.find(key):
      x = self.root
      y = None

      while x is not None: 
        y = x
        if(key < y.key):
          x = x.left
        elif(y.key < key):
          x = x.right
        else:
          # rootが対象のノードの場合
          break
        if(x.key == key):
          break

      # yが親、子のxがdeleteの対象
      x_children  = [c for c in [x.left, x.right] if c is not None]
      if len(x_children) == 0:
        # 親から子の情報を削除
        for c in [y.left, y.right]:
          if c is not None and c.key == key:
            # yの左右どっちにcがあるのか同定してx_children[0]をぶちこむ
            which_side = [i for i, x in enumerate([y.left, y.right]) if x is not None and x.key == c.key][0]
            if which_side == 0:
              # 左側
              y.left = None
            else:
              # 右側
              y.right = None
      elif len(x_children) == 1:
        # 子の子を親の子にする（字面が妙な雰囲気）
        for c in [y.left, y.right]:
          if c is not None and c.key == key:
            # yの左右どっちにcがあるのか同定してx_children[0]をぶちこむ
            which_side = [i for i, x in enumerate([y.left, y.right]) if x is not None and x.key == c.key][0]
            if which_side == 0:
              # 左側
              y.left = x_children[0]
            else:
              # 右側
              y.right = x_children[0]
      else:
        # 削除予定の子から左側のうち最大のものをとってきて、削除予定のやつを削除したのちそこに入れる
        # とやったらなぜか右側の最小値で出すのが想定される解らしい どっちでもあってんだろが
        min_child = x.right
        # 一つ上の親を保持
        par = x
        while True:
          if min_child.left is None:
            break
          par = min_child
          min_child = min_child.left

        if(par.key == key):
          # 初っ端で終了した（下る世代の数が1）
          pass
        else:
          # 下る世代の数が1より多い
          par.left = None
          min_child.right = x.right
          
        # 大本の削除対象のxの親であるyの左右どちらがxであるか同定し更新
        x_side = [i for i, s in enumerate([y.left, y.right]) if s is not None and s.key == x.key][0]
        # それを直接min_childとする
        if x_side == 0:
          # 左
          y.left = min_child
        else:
          # 右
          y.right = min_child
        # 更新
        min_child.left = x.left
      
n = int(input())
bst = BST()
for _ in range(n):
  query = input().split()
  if query[0] == "insert":
    bst.insert(int(query[1]))
  elif query[0] == "find":
    print("yes" if bst.find(int(query[1])) else "no")
  elif query[0] == "print":
    # 中間巡回順, 先行巡回順
    root = bst.root
    bst.inorder(root)
    print()
    bst.preorder(root)
    print()
  elif query[0] == "delete":
    bst.delete(int(query[1]))

Submission status: Accepted

Solution code:
class Node:
    def __init__(self, key):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None
class Tree:
    def __init__(self):
        self.root = None
        self.inorder = []
        self.preorder = []

    def insert(self, node):

        p = None
        x = self.root        
        while x is not None:
            p = x
            # print(node.key, x.key)
            if node.key <= x.key:
                x = x.left
            else:
                x = x.right

        # insertするnodeの親を設定
        node.parent = p

        if p is None:
            self.root = node
        else:
            # insertするnodeを親のleftかrightに設定
            if node.key <= p.key:
                # print('leftに設定')
                p.left = node
            else:
                # print('rightに設定')
                p.right = node

    def find(self, key):
        # print('find: ', str(key))
        node = self.root
        while node is not None:
            if node.key == key:
                return node
            elif key <= node.key:
                node = node.left
            else:
                node = node.right
        return None

    def delete(self, z):
        # print("delete =========", z.key)
        # print(z.key)
        # print(z.parent)
        p = z.parent
        # print(p.key)

        # 1. zが子を持たない場合
        if z.left is None and z.right is None:
            # print('pattern 1')
            if p.left == z:
                p.left = None
            else:
                p.right = None

        # 3. zが子を2つ持つ場合
        elif z.left is not None and z.right is not None:
            # print('pattern 2')
            next_node = tree.get_next_node(z)
            # print('next:', next_node.key)
            z.key = next_node.key
            self.delete(next_node)

        # 2. zがちょうど1つの子を持つ場合
        else:
            # print('pattern 3')
            # zが左子だった場合
            if p.left == z:
                if z.left is not None:
                    p.left = z.left
                    z.left.parent = p
                else:
                    p.left = z.right
                    z.right.parent = p
            else:
                # zが右子だった場合
                if z.left is not None:
                    p.right = z.left
                    z.left.parent = p
                else:
                    p.right = z.right
                    z.right.parent = p

    def get_next_node(self, node):
        if node.right is not None:
            # print('node right is not none')
            return self.get_minimum(node.right)
        p = x.parent
        while p is not None and p != p.parent.left:
            p = p.parent
        return p.parent

    def get_minimum(self, node):
        x = node
        # print('find1 :', x.key)
        while x.left is not None:
            x = x.left
            # print('find2 :', x.key)
        return x

    def print_inorder(self):
        self.inorder = []
        self.inorder_traverse(self.root)
        print(' ' + ' '.join(map(str, self.inorder)))

    def print_preorder(self):
        self.preorder = []
        self.preorder_traverse(self.root)
        print(' ' + ' '.join(map(str, self.preorder)))

    def inorder_traverse(self, node):
        if node is None:
            return
        self.inorder_traverse(node.left)
        self.inorder.append(node.key)
        self.inorder_traverse(node.right)

    def preorder_traverse(self, node):
        if node is None:
            return
        self.preorder.append(node.key)
        self.preorder_traverse(node.left)
        self.preorder_traverse(node.right)

tree = Tree()
m = int(input())
for i in range(m):
    line = input().split()
    if line[0] == 'print':
        # print('root', str(tree.root.key))
        tree.print_inorder()
        tree.print_preorder()
        # print('root:(30)', tree.root.key)
        # print('root.left(17):', tree.root.left.key)
        # print('root.left.left(X):', tree.root.left.left.key)
        # print('root.left.right(X):', tree.root.left.right.key)
        # print('-----------------')
    elif line[0] == 'insert':
        key = int(line[1])
        tree.insert(Node(key))
    elif line[0] == 'find':
        key = int(line[1])
        if tree.find(key):
            print('yes')
        else:
            print('no')
    elif line[0] == 'delete':
        
        # print("current tree----")
        # print(tree.root.key)
        # print(tree.root.left.key)
        # print(tree.root.left.right.key)
        # print(tree.root.left.right.parent.key)
        # print("current tree----")
        key = int(line[1])
        # print('delete', str(key))
        node = tree.find(key)
        # print('node.key', node.key)
        tree.delete(node)



# print('root.left.right:', tree.root.left.right.left.key)
# print('root:', tree.root.left.right.right.key)

Submission status: Accepted

Solution code:
from sys import stdin

class TreeNode:
    def __init__(self,key,val,left=None,right=None,parent=None):
        self.key = key
        self.payload = val
        self.leftChild = left
        self.rightChild = right
        self.parent = parent

    def hasLeftChild(self):
        return self.leftChild

    def hasRightChild(self):
        return self.rightChild

    def isLeftChild(self):
        return self.parent and self.parent.leftChild == self

    def isRightChild(self):
        return self.parent and self.parent.rightChild == self

    def isRoot(self):
        return not self.parent

    def isLeaf(self):
        return not (self.rightChild or self.leftChild)

    def hasAnyChildren(self):
        return self.rightChild or self.leftChild

    def hasBothChildren(self):
        return self.rightChild and self.leftChild

    def spliceOut(self):
        if self.isLeaf():
            if self.isLeftChild():
                self.parent.leftChild = None
            else:
                self.parent.rightChild = None
        elif self.hasAnyChildren():
            if self.hasLeftChild():
                if self.isLeftChild():
                    self.parent.leftChild = self.leftChild
                else:
                    self.parent.rightChild = self.leftChild
                self.leftChild.parent = self.parent
            else:
                if self.isLeftChild():
                    self.parent.leftChild = self.rightChild
                else:
                    self.parent.rightChild = self.rightChild
                    self.rightChild.parent = self.parent

    def findSuccessor(self):
        succ = None
        if self.hasRightChild():
            succ = self.rightChild.findMin()
        else:
            if self.parent:
                    if self.isLeftChild():
                        succ = self.parent
                    else:
                        self.parent.rightChild = None
                        succ = self.parent.findSuccessor()
                        self.parent.rightChild = self
        return succ

    def findMin(self):
        current = self
        while current.hasLeftChild():
            current = current.leftChild
        return current

    def replaceNodeData(self,key,value,lc,rc):
        self.key = key
        self.payload = value
        self.leftChild = lc
        self.rightChild = rc
        if self.hasLeftChild():
            self.leftChild.parent = self
        if self.hasRightChild():
            self.rightChild.parent = self

class BinarySearchTree:
    def __init__(self):
        self.root = None
        self.size = 0

    def length(self):
        return self.size

    def __len__(self):
        return self.size

    def put(self,key,val):
        if self.root:
            self._put(key,val,self.root)
        else:
            self.root = TreeNode(key,val)
        self.size = self.size + 1

    def _put(self,key,val,currentNode):
        if key < currentNode.key:
            if currentNode.hasLeftChild():
                   self._put(key,val,currentNode.leftChild)
            else:
                   currentNode.leftChild = TreeNode(key,val,parent=currentNode)
        else:
            if currentNode.hasRightChild():
                   self._put(key,val,currentNode.rightChild)
            else:
                   currentNode.rightChild = TreeNode(key,val,parent=currentNode)

    def __setitem__(self,k,v):
        self.put(k,v)

    def get(self,key):
        if self.root:
            res = self._get(key,self.root)
            if res:
                   return res.payload
            else:
                   return None
        else:
            return None

    def _get(self,key,currentNode):
        if not currentNode:
            return None
        elif currentNode.key == key:
            return currentNode
        elif key < currentNode.key:
            return self._get(key,currentNode.leftChild)
        else:
            return self._get(key,currentNode.rightChild)

    def __getitem__(self,key):
        return self.get(key)

    def __contains__(self,key):
        if self._get(key,self.root):
            return True
        else:
            return False

    def print_nodes(self):
        A = [] # Preorder
        B = [] # Inorder
        def walk_tree(u):
            if u == None:
                return
            r = u.rightChild
            l = u.leftChild
            A.append(u.key)
            walk_tree(l)
            B.append(u.key)
            walk_tree(r)

        walk_tree(self.root)
        print(" ", end="")
        print(*B, sep=" ")
        print(" ", end="")
        print(*A, sep=" ")

    def delete(self,key):
        if self.size > 1:
            nodeToRemove = self._get(key,self.root)
            if nodeToRemove:
                self.remove(nodeToRemove)
                self.size = self.size-1
            else:
                raise KeyError('Error, key not in tree')
        elif self.size == 1 and self.root.key == key:
            self.root = None
            self.size = self.size - 1
        else:
            raise KeyError('Error, key not in tree')

    def __delitem__(self,key):
        self.delete(key)

    def remove(self,currentNode):
        if currentNode.isLeaf(): #leaf
            if currentNode == currentNode.parent.leftChild:
                currentNode.parent.leftChild = None
            else:
                currentNode.parent.rightChild = None
        elif currentNode.hasBothChildren(): #interior
            succ = currentNode.findSuccessor()
            succ.spliceOut()
            currentNode.key = succ.key
            currentNode.payload = succ.payload

        else: # this node has one child
            if currentNode.hasLeftChild():
                if currentNode.isLeftChild():
                    currentNode.leftChild.parent = currentNode.parent
                    currentNode.parent.leftChild = currentNode.leftChild
                elif currentNode.isRightChild():
                    currentNode.leftChild.parent = currentNode.parent
                    currentNode.parent.rightChild = currentNode.leftChild
                else:
                    currentNode.replaceNodeData(currentNode.leftChild.key,
                                    currentNode.leftChild.payload,
                                    currentNode.leftChild.leftChild,
                                    currentNode.leftChild.rightChild)
            else:
                if currentNode.isLeftChild():
                    currentNode.rightChild.parent = currentNode.parent
                    currentNode.parent.leftChild = currentNode.rightChild
                elif currentNode.isRightChild():
                    currentNode.rightChild.parent = currentNode.parent
                    currentNode.parent.rightChild = currentNode.rightChild
                else:
                    currentNode.replaceNodeData(currentNode.rightChild.key,
                                    currentNode.rightChild.payload,
                                    currentNode.rightChild.leftChild,
                                    currentNode.rightChild.rightChild)

def read_and_print_BSTree(bst, n):
    for _ in range(n):
        cmd = stdin.readline().strip().split()
        if cmd[0] == 'insert':
            bst.put(int(cmd[1]), int(cmd[1]))
        elif cmd[0] == 'print':
            bst.print_nodes()
        elif cmd[0] == 'find':
            if bst.get(int(cmd[1])):
                print('yes')
            else:
                print('no')
        elif cmd[0] == 'delete':
            bst.delete(int(cmd[1]))

def __main():
    n = int(input())
    bst = BinarySearchTree()
    read_and_print_BSTree(bst, n)

if __name__ == '__main__':
    __main()

Submission status: Accepted

Solution code:
import sys
class Tree():
    def __init__(self):
        self.root = None
    def insert(self, key):
        z = Node(key)
        y = None
        x = self.root
        while x:
            y = x
            if z.key < x.key:
                x = x.left
            else:
                x = x.right
        z.parent = y
        if y == None:
            self.root = z
        elif z.key < y.key:
            y.left = z
        else:
            y.right = z
    def find(self, key):
        x = self.root
        while x and x.key != key:
            if x.key < key:
                x = x.right
            else:
                x = x.left
        return x
    def delete(self, key):
        z = self.find(key)
        y = self.successor(z) if z.left and z.right else z
        x = y.left if y.left else y.right

        if x:
            x.parent = y.parent
        if y.parent == None:
            self.root = x 
        elif y == y.parent.left:
            y.parent.left = x
        else:
            y.parent.right = x
        if y != z:
            z.key = y.key
    def successor(self, x):
        if x.right:
            return self.minimum(x.right)
        y = x.parent
        while y and x == y.right:
            x = y
            y = y.parent
        return y

    def minimum(self, x):
        while x.left:
            x = x.left
        return x
    
    def print(self):
        print('',' '.join(map(str, self.root.inwalk())))
        print('',' '.join(map(str, self.root.prewalk())))
    
class Node():
    def __init__(self, key):
        self.key = key
        self.parent = self.left = self.right = None
    def prewalk(self):
        ret = [self.key]
        if self.left:
            ret += self.left.prewalk()
        if self.right:
            ret += self.right.prewalk()
        return ret
    def inwalk(self):
        ret = []
        if self.left:
            ret += self.left.inwalk()
        ret += [self.key]
        if self.right:
            ret += self.right.inwalk()
        return ret
tree = Tree()
n = sys.stdin.readline()
for line in sys.stdin:
    if line[0] == 'i':
        tree.insert(int(line.split()[1]))
    elif line[0] == 'f':
        print('yes' if tree.find(int(line.split()[1])) else 'no')
    elif line[0] == 'd':
        tree.delete(int(line.split()[1]))            
    else:
        tree.print()

Submission status: Accepted

Solution code:
import sys
 
class TreeNode:
    def __init__(self, val):
        self.val = val
        self.left = self.right = None
    
    def __eq__(self, other):
        return self.val == other.val
 
class BST:
    def __init__(self):
        self.root = None
     
    def insert(self, node):
        def helper(root):
            y, x = None, root
            while isinstance(x, TreeNode):
                y = x
                if node.val < x.val:
                    x = x.left
                else:
                    x = x.right
            if y is None:
                root = node
            elif node.val < y.val:
                y.left = node
            else:
                y.right = node
            return root
             
        self.root = helper(self.root)
 
    def find(self, val):
        def helper(root):
            if root is None:
                return None
            elif root.val == val:
                return root
            elif val < root.val:
                return helper(root.left)
            else:
                return helper(root.right)
        return helper(self.root)
        
    def delete(self, val):
        node = TreeNode(val)
        def findMin(root):
            while root.left is not None:
                root = root.left
            return root
        
        def helper(root, node):
            if root is None:
                return None
            elif root == node:
                if root.left is None:
                    root = root.right
                elif root.right is None:
                    root = root.left
                else:
                    tmp = findMin(root.right)
                    root.val = tmp.val
                    rr = helper(root.right, TreeNode(tmp.val))
                    root.right = rr
                return root
            else:
                if node.val < root.val:
                    root.left = helper(root.left, node)
                else:
                    root.right = helper(root.right, node)
                return root

        helper(self.root, node)

    def inorder(self):
        def helper(root):
            return [] if root is None else helper(root.left) + [root.val] + helper(root.right)
        return helper(self.root)
 
    def preorder(self):
        def helper(root):
            return [] if root is None else [root.val] + helper(root.left) + helper(root.right)
        return helper(self.root)
 
if __name__ == '__main__':
    q = sys.stdin.readline()
    q = int(q)
    bst = BST()
    for _ in range(q):
        tmp = sys.stdin.readline()
        if tmp.startswith('print'):
            print ' ' + ' '.join(map(lambda x: str(x), bst.inorder()))
            print ' ' + ' '.join(map(lambda x: str(x), bst.preorder()))
        elif tmp.startswith('insert'):
            _, val = tmp.split()
            node = TreeNode(int(val))
            bst.insert(node)
        elif tmp.startswith('find'):
            _, val = tmp.split()
            print ('yes' if bst.find(int(val)) is not None else 'no')
        else:
            _, val = tmp.split()
            bst.delete(int(val))