Skip to content

Instantly share code, notes, and snippets.

@lettergram
Created March 14, 2015 04:00
Show Gist options
  • Save lettergram/739aa49ccc3d75db304f to your computer and use it in GitHub Desktop.
Save lettergram/739aa49ccc3d75db304f to your computer and use it in GitHub Desktop.
Binary Search Tree
'''
A classic node class for use in a tree
'''
class Node:
def __init__(self,data):
self.left = None
self.right = None
self.data = data
'''
Creates a general Binary Tree
'''
class BinaryTree(Node):
def __init__(self):
self.root = None
def insert(self, root, data):
if root is None:
root = Node(data)
elif(data <= root.data):
root.left = self.insert(root.left,data)
elif(data > root.data):
root.right = self.insert(root.right,data)
return root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment