-
-
Save pasali/5470468 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 | |
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): | |
sayac = 1 | |
if self.left !=None: | |
sayac += self.left.kacDugum() | |
if self.right!=None: | |
sayac += self.right.kacDugum() | |
return sayac | |
b=BinaryTree("a") | |
b.insertLeft("b") | |
b.insertRight("c") | |
b.left.insertLeft("d") | |
b.left.insertRight("e") | |
b.right.insertLeft("f") | |
print 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