Created
March 14, 2015 04:00
-
-
Save lettergram/739aa49ccc3d75db304f to your computer and use it in GitHub Desktop.
Binary Search Tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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