Skip to content

Instantly share code, notes, and snippets.

@wethinkagile
Created May 31, 2014 13:13
Show Gist options
  • Save wethinkagile/1a96ca0e056a5e968c1c to your computer and use it in GitHub Desktop.
Save wethinkagile/1a96ca0e056a5e968c1c to your computer and use it in GitHub Desktop.
class BinaryTree:
def __init__(self,rootObj):
self.key = rootObj
self.leftChild = None
self.rightChild = None
def getRightChild(self):
return self.rightChild
def getLeftChild(self):
return self.leftChild
def getRootVal(self):
return self.key
def setRootVal(self,obj):
self.key = obj
def insertLeft(self,newNode):
if self.leftChild == None:
self.leftChild = BinaryTree(newNode)
else:
temp = BinaryTree(newNode)
temp.leftChild = self.leftChild
self.leftChild = temp
def insertRight(self,newNode):
if self.rightChild == None:
self.rightChild = BinaryTree(newNode)
else:
temp = BinaryTree(newNode)
temp.rightChild = self.rightChild
self.rightChild = temp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment