Advertisement
Guest User

Untitled

a guest
Jun 17th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. class Node:
  2. def __init__(self, data = None):
  3.  
  4. self.left = None
  5. self.right = None
  6. self.count = 1
  7. self.data = data
  8.  
  9. def insert(self, data):
  10. if self.data:
  11. if data < self.data:
  12. if self.left is None:
  13. self.left = Node(data)
  14. else:
  15. self.left.insert(data)
  16. elif data > self.data:
  17. if self.right is None:
  18. self.right = Node(data)
  19. else:
  20. self.right.insert(data)
  21. else :
  22. self.count = self.count + 1
  23. else:
  24. self.data = data
  25. self.count = 1
  26.  
  27.  
  28. def PrintTree(self):
  29. if self.left:
  30. self.left.PrintTree()
  31. print( self.data , self.count),
  32. if self.right:
  33. self.right.PrintTree()
  34.  
  35.  
  36. root = Node()
  37. root.insert("Schimur")
  38. root.insert("ist")
  39. root.insert("der")
  40. root.insert("schlechteste")
  41. root.insert("schlechteste")
  42. root.insert("schlechteste")
  43. root.insert("Bardo")
  44. root.insert("top")
  45.  
  46. root.PrintTree()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement