Impressions of Week 7
This week 7 is also about BTNode. The things in lab is hard but fun. In the lab we need to write functions to find:
1.height
2.node with maximum data
3.insert data
4.whether tree contains a specific value
5.whether tree rooted at node contains value
6.delete node that has the specific data
7.find node with a specific data
8. the result of evaluate
9.the result of parentesize
10.the list between a specific value of start and a specific value of end
11.the list of internal between a specific value of start and a specific value of end
12.the lis of data in the longest path
13.check a node is a leaf or not
14.preorder_visit
15.postorder_visit
Every thing is hard and had taken me lots of time to think and write about, but after I finished the lab I feel I won a war: BTNode is not as hard as before. I could easily find the height by using function like:
return 1 + max(height(node.left), height(node.right)) if node else 0
And easily find the hardest part -- parentezise by using:
if is_leaf(b):
return str(b.data)
else:
# produce the string expression, then evaluate it
return '({}{}{})'.format(parenthesize(b.left), str(b.data), parenthesize(b.right))
I think I could handle the BTNode easier than before.
没有评论:
发表评论