()
| 19 | |
| 20 | |
| 21 | def build_tree(): |
| 22 | print("\n********Press N to stop entering at any point of time********\n") |
| 23 | print("Enter the value of the root node: ", end="") |
| 24 | check = raw_input().strip().lower() |
| 25 | if check == 'n': |
| 26 | return None |
| 27 | data = int(check) |
| 28 | q = queue.Queue() |
| 29 | tree_node = TreeNode(data) |
| 30 | q.put(tree_node) |
| 31 | while not q.empty(): |
| 32 | node_found = q.get() |
| 33 | print("Enter the left node of %s: " % node_found.data, end="") |
| 34 | check = raw_input().strip().lower() |
| 35 | if check == 'n': |
| 36 | return tree_node |
| 37 | left_data = int(check) |
| 38 | left_node = TreeNode(left_data) |
| 39 | node_found.left = left_node |
| 40 | q.put(left_node) |
| 41 | print("Enter the right node of %s: " % node_found.data, end="") |
| 42 | check = raw_input().strip().lower() |
| 43 | if check == 'n': |
| 44 | return tree_node |
| 45 | right_data = int(check) |
| 46 | right_node = TreeNode(right_data) |
| 47 | node_found.right = right_node |
| 48 | q.put(right_node) |
| 49 | |
| 50 | |
| 51 | def pre_order(node): |
no test coverage detected