This week we learned the Class BTNode, which is a way to output a tree which every node only has two children. In this class, we use self. data, self.left and self.right to donates the node, two children respectively.
However, the most important part is the writing recursion, we use the recursion to calculate some values of the tree, such as the longest path or the number of nodes. The way to write recursion is similar as before, it is using if statement to calculate the simplest situation and else statement to write the function to call itself for the complex situation.
For me, I spend a lot of time to think about how to convert string '*' to the operation *, TA and me discuss with it, finally, he gives me a quick way to do that: eval(str(self.left)+self.data +str(self.right)), so that we can do not use four if statement to evaluate the operation of the self.data.
I'm so thankful for my TA, I heard that he will strike next week, I feel so sad. He is very patient guy; every lab, I ask him so much questions that I didn't understand in class.
Anyway, although the strike will influence us, we will still work hard.
No comments:
Post a Comment