title: Binary searchtree, trying to implement a remove node method, trouble with pointers
body: <p>I found another good thread here at stackoverflow, gonna link it <a href="https://stackoverflow.com/questions/26568163/removing-a-node-from-a-binary-search-tree-using-recursion">removing a node from a binary search tree using recursion</a> . Here is where I've taken the code from, its looking like this:</p>
  
  <pre><code>import random
  from time import time
  
  class BinaryNode:
  
      def __init__(self, value = None):
          """Create binary node"""
          self.value = value
          self.left = None
          self.right = None
  
      def add(self, val):
          """Adds a new node to the tree containing this value"""
          if val &lt;= self.value:
              if self.left:
                  self.left.add(val)
              else:
                  self.left = BinaryNode(val)
          else:
              if self.right:
                  self.right.add(val)
              else:
                  self.right = BinaryNode(val)
  
      def delete(self):
          """
           Remove value of self from BinaryTree. Works in conjunction with remove
           method in BinaryTree
          """
  
          if self.left == self.right == None:
              return None
          if self.left == None:
              return self.right
          if self.right == None:
              return self.left
  
          child = self.left
          grandchild = child.right
          if grandchild:
              while grandchild.right:
                  child = grandchild
                  grandchild = child.right
              self.value = grandchild.value
              child.right = grandchild.left
          else:
              self.left = child.left
              self.value = child.value
  
          return self
  
  class BinaryTree:
  
      def __init__(self):
          """Create empty binary tree"""
          self.root = None
  
      def add(self, value):
          """Insert value into proper location in Binary Tree"""
          if self.root is None:
              self.root = BinaryNode(value)
          else:
              self.root.add(value)
  
      def contains(self, target):
          """Check whether BST contains target value"""
  
          node = self.root
          while node:
              if target == node.value:
                  return True
              if target &lt; node.value:
                  node = node.left
              else:
                  node = node.right
  
          return False
  
      def remove(self, value):
          """Remove value from tree"""
  
          if self.root:
              self.root = self.removeFromParent(self.root, value)
  
      def removeFromParent(self, parent, value):
          """remove value from tree rooted at parent"""
          if parent is None:
              return None
  
          if value == parent.value:
              return parent.delete()
          elif value &lt; parent.value:
              parent.left = self.removeFromParent(parent.left, value)
          else:
              parent.right = self.removeFromParent(parent.right, value)
  
          return parent
  </code></pre>
  
  <p>If we focus on the <code>delete</code> method under the <code>BinaryNode</code> class, I need some help understand the pointers, I have put together my own binary searchtree before but I cannot understand, is <code>self.left</code> a pointer? What is <code>self.left.right</code> (see <code>grandchild</code>), is this a pointer from the "start", soon to be root, to the child, and then to right (to the grandchild). It also feels a bit weird for me that the <code>delete</code> method doesn't need an argument with which value to remove, I dont see anywhere else using that method...</p>