Skip to content

Instantly share code, notes, and snippets.

Created March 14, 2015 04:00
What would you like to do?
Binary Search Tree
A classic node class for use in a tree
class Node:
def __init__(self,data):
self.left = None
self.right = None = 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.left = self.insert(root.left,data)
elif(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