Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Tree(object):
- def __init__(self):
- self.left = None
- self.right = None
- self.data = None
- print(" For a 20x20 grid")
- Matrix = [[0 for x in range(3)] for y in range(3)]
- print("0 matrix created: ",Matrix)
- val = 1
- for i in range(3):
- for j in range(3):
- Matrix[i][j] = val
- val += 1
- print("Populaed matrix: ",Matrix)
- def populateMat(node,i,j,matrix):
- if i < 3 and j+1 < 3:
- print(i,j)
- right_node = Tree()
- right_node.data = matrix[i][j+1]
- print("right node: ",right_node.data)
- node.right = populateMat(right_node,i+1,j,matrix)
- if j < 3 and i+1 < 3:
- print(i,j)
- left_node = Tree()
- left_node.data = matrix[i+1][j]
- print("left node: ",left_node.data)
- node.left = populateMat(left_node,i,j+1,matrix)
- root = Tree()
- root.data = Matrix[0][0]
- populateMat(root,0,0,Matrix)
- print(root.right)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement