Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Node:
- def __init__(self, data = None):
- self.left = None
- self.right = None
- self.count = 1
- self.data = data
- def insert(self, data):
- if self.data:
- if data < self.data:
- if self.left is None:
- self.left = Node(data)
- else:
- self.left.insert(data)
- elif data > self.data:
- if self.right is None:
- self.right = Node(data)
- else:
- self.right.insert(data)
- else :
- self.count = self.count + 1
- else:
- self.data = data
- self.count = 1
- def PrintTree(self):
- if self.left:
- self.left.PrintTree()
- print( self.data , self.count),
- if self.right:
- self.right.PrintTree()
- root = Node()
- root.insert("Schimur")
- root.insert("ist")
- root.insert("der")
- root.insert("schlechteste")
- root.insert("schlechteste")
- root.insert("schlechteste")
- root.insert("Bardo")
- root.insert("top")
- root.PrintTree()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement