Created
April 26, 2013 20:46
-
-
Save emreyh/5470318 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 BinaryTree: | |
def __init__(self,rootObj): | |
self.key=rootObj | |
self.left = None | |
self.right = None | |
self.sayac=1 | |
def insertLeft(self,newNode): | |
if self.left == None: | |
self.left = BinaryTree(newNode) | |
else: | |
t = BinaryTree(newNode) | |
t.left = self.left | |
self.left = t | |
def insertRight(self,newNode): | |
if self.right == None: | |
self.right = BinaryTree(newNode) | |
else: | |
t = BinaryTree(newNode) | |
t.right = self.right | |
self.right = t | |
def getRootVal(self): | |
return self.key | |
def kacDugum(self): | |
if self.left !=None: | |
self.sayac+=1 | |
self.left.kacDugum() | |
if self.right!=None: | |
self.sayac+=1 | |
self.right.kacDugum() | |
print self.sayac | |
b=BinaryTree("a") | |
b.insertLeft("b") | |
b.insertRight("c") | |
b.left.insertLeft("d") | |
b.left.insertRight("e") | |
b.right.insertLeft("f") | |
b.kacDugum() | |
def sol_endip(root): | |
if root.left!=None: | |
sol_endip(root.left) | |
return root.key | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment