Advertisement
stefbrad15

binarytreeattempt1

Mar 26th, 2017
386
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """ Node is defined as
  2. class node:
  3.    def __init__(self, data):
  4.        self.data = data
  5.        self.left = None
  6.        self.right = None
  7. """
  8.  
  9. def check_binary_search_tree_(root, values = None):
  10.     #print root.data
  11.     #print root.left
  12.     #print root.right
  13.    
  14.     toReturn = True
  15.    
  16.     if values == None:
  17.         values = dict()
  18.        
  19.     if not root.data in values:
  20.         values[root.data] = True
  21.     else:
  22.         return False
  23.    
  24.     if (root.left):
  25.         if (root.left.data > root.data):
  26.             return False
  27.         else:
  28.             toReturn = check_binary_search_tree_(root.left)
  29.    
  30.     if (root.right):
  31.         if (root.right.data < root.data):
  32.             return False
  33.         else:
  34.             toReturn = check_binary_search_tree_(root.right)    
  35.     return toReturn
Advertisement
RAW Paste Data Copied
Advertisement