Created
May 26, 2011 17:05
-
-
Save selenamarie/993524 to your computer and use it in GitHub Desktop.
simple binary tree implementation
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 Tree: | |
def __init__(self): | |
self.left = None | |
self.right = None | |
self.operator = None | |
def to_array(self): | |
new_array = [] | |
new_array.append(self.operator) | |
for node in [self.left, self.right]: | |
if isinstance(node, Tree): | |
new_array.append(node.to_array()) | |
elif isinstance(node, list): | |
new_array.append(node) | |
return new_array | |
def to_json(self): | |
return json.dumps(self.to_array()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment