@BlueBowser/

# NodeTree

## No description

Files
• main.py
• node.py
main.py
```1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
```
```from node import Node

tree = Node(0)

#           0
#        /     \
#        2      3
#      /   \     \
#      5    6     7

L = Node(2)
R = Node(3)
LL = Node(5)
LR = Node(6)
RR = Node(7)

tree.left = L
tree.right = R
tree.left.left = LL
tree.left.right = LR
tree.right.right = RR

def inorder(noderoot):
''' Find root node's transversals, returns tuple. Maybe inclue a process where you call the function until you are at the bottom of the tree.
'''
if noderoot:
a = noderoot.value
b = inorder(noderoot.left)
c = inorder(noderoot.right)
return (a, b, c)

def find(num, node):
nodenum = inorder(node)

if node is None:
return 'nothing here'

nv = None
try:
nv = nodenum[0]
except TypeError:
print('Uh oh! Value is NULL')

if nv == num:
print(num, ' at ', node)
else:
find(num, node.left)
find(num, node.right)

print()
find(2, tree)

'''
************************************
*  anything below here are drafts of    *  ideas
*
************************************
'''

'''
New! Use inorder (Left - Root - Right) to find the node triplets!

Recursion: Function calls itself and makes a loop:
must have a base case(when function stops)
and a recursive case(what function does while repeating)
'''
"""
def retLevel(node, level):
'''Transverses the tree by row, returns two number tuples
'''
if Node is None:
pass
elif level == 1:
try:
return node.value
except AttributeError:
pass
elif level > 1:
return retLevel(node.left, level - 1), retLevel(node.right, level - 1)

def PLO(node):
h = maxDepth(node)
for i in range(1, h + 1):
print(retLevel(node, i))
"""

"""
def maxDepth(nobj):
'''Returns maximum depth of tree
'''
if nobj is None:
return 0
else:
ldpth = maxDepth(nobj.left)
rdpth = maxDepth(nobj.right)

if ldpth > rdpth:
return ldpth + 1

else:
return rdpth + 1
"""

```