SHARE
TWEET

Untitled

a guest Mar 18th, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Tree:
  2.     def __init__(self,value):
  3.         self.root = value
  4.         self.left = None
  5.         self.right = None
  6.  
  7.  
  8. class MyComparableKey():
  9.     def __init__(self, int_value, string_value):
  10.         self.int_value = int_value
  11.         self.string_value = string_value
  12.  
  13.     def __lt__(self, other):
  14.        return self.int_value < other.int_value
  15.  
  16. class BST:
  17.     def __init__(self):
  18.         self.root = None
  19.     def insert(self,key, data):
  20.         value = MyComparableKey(key,data)
  21.         if self.root == None:
  22.             self.root = Tree(value)
  23.         else:
  24.             self._ins(value,self.root)
  25.     def _ins(self,value,node):
  26.         if node == None:
  27.             node = Tree(value)
  28.         elif node.root < value:
  29.             self._ins(value,node.left)
  30.         elif value < node.root:
  31.             self._ins(value,node.right)
  32.         else:
  33.             raise ItemExistsException()
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