Created
May 18, 2016 13:40
-
-
Save MarshallOfSound/2c93ea55be4688422c7c9632e70ebbeb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Node: | |
""" | |
Tree node: left and right child + data which can be any object | |
""" | |
def __init__(self, data=None): | |
""" | |
Node constructor | |
@param data node data object | |
""" | |
self.left = None | |
self.right = None | |
self.data = data | |
def insert(self, data): | |
""" | |
Insert new node with data | |
@param data: Node data object to insert | |
""" | |
if self.data: | |
if data < self.data: | |
if self.left is None: | |
self.left = Node(data) | |
else: | |
self.left.insert(data) | |
else: | |
if self.right is None: | |
self.right = Node(data) | |
else: | |
self.right.insert(data) | |
else: | |
self.data = data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment