P3_utility.py
811 Bytes
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
def printMatrix(d):
m = len(d)
n=len(d[0])
for i in range(0,m):
for j in range(0,n):
print("%4d" % d[i][j]," ")
print()
#print float matrix
def printMatrixF(d):
n=len(d[0])
for i in range(0,n):
for j in range(0,n):
print("%5.2f" % d[i][j]," ")
print()
def print_inOrder(root):
if not root:
return
print_inOrder(root.l_child)
print(root.data)
print_inOrder(root.r_child)
def print_preOrder(root):
if not root:
return
print(root.data)
print_preOrder(root.l_child)
print_preOrder(root.r_child)
def print_postOrder(root):
if not root:
return
print_postOrder(root.l_child)
print_postOrder(root.r_child)
print(root.data)