Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. class Tree(object):
  2. def __init__(self):
  3. self.left = None
  4. self.right = None
  5. self.data = None
  6.  
  7. print(" For a 20x20 grid")
  8. Matrix = [[0 for x in range(3)] for y in range(3)]
  9. print("0 matrix created: ",Matrix)
  10. val = 1
  11. for i in range(3):
  12. for j in range(3):
  13. Matrix[i][j] = val
  14. val += 1
  15. print("Populaed matrix: ",Matrix)
  16. def populateMat(node,i,j,matrix):
  17. if i < 3 and j+1 < 3:
  18. print(i,j)
  19. right_node = Tree()
  20. right_node.data = matrix[i][j+1]
  21. print("right node: ",right_node.data)
  22. node.right = populateMat(right_node,i+1,j,matrix)
  23. if j < 3 and i+1 < 3:
  24. print(i,j)
  25. left_node = Tree()
  26. left_node.data = matrix[i+1][j]
  27. print("left node: ",left_node.data)
  28. node.left = populateMat(left_node,i,j+1,matrix)
  29. root = Tree()
  30. root.data = Matrix[0][0]
  31. populateMat(root,0,0,Matrix)
  32. print(root.right)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement