daily pastebin goal
72%
SHARE
TWEET

Nicolas Dumazet

a guest Dec 21st, 2010 565 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Node(object):
  2.   ...
  3.   def children_count(self):
  4.     """
  5.    Returns the number of children
  6.  
  7.    @param node node to get nb of children
  8.    @returns number of children: 0, 1, 2
  9.    """
  10.     cnt = 0
  11.     if self.left:
  12.       cnt += 1
  13.     if self.right:
  14.       cnt += 1
  15.     return cnt
  16.  
  17.   def delete(self, data):
  18.     node, parent = self.lookup(data)
  19.     if node is None:
  20.       return
  21.     children_count = node.children_count()
  22.     if children_count == 0:
  23.       # if node has no children, just remove it
  24.       if parent.left is node:
  25.         parent.left = None
  26.       else:
  27.         parent.right = None
  28.     elif children_count == 1:
  29.   ...
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top