This week is kind of busy
for me…. T^T Yet, I have been quite enjoy to be busy. :D As long As there is no
tests or exams. :D
Anyway, this week, nothing
every important or special happened; yet, this week’s lab is kind of
interesting. The handout asked us to write the function/method count_less(self,
item) for three times. This function /method needs to return the number of
nodes in this BST with items that are less than given item.
The first time, we need to
write it as a recursive method in the file BST rec1.py within the classBST(object),
and we need write a nested helper function within count_less(self, item) without
changing or adding anything to the class _BSTNode.
The second time, we still
need to write it as a method in the file BST rec2.py within the classBST(object),
but we need to write the helper method in class _BSTNode and calling the helper
within count_less(self, item) and without changing or adding anything to the
class BST.
Finally, the last time, we
will implement method count_less(self, item) in class BST, yet we also need to
write a helper method in both class _BSTNode and _BSTNone and calling the
helper within count_less(self, item) without changing or adding anything to the
class BST.
My partner and I were
confused at first, wondering why we need to do the same thing again and again in
three difference ways. Things turned out to be really interesting: the first
time is just a bit challenging for us to come up with the solution, the second
way is just want us to learn the way to import a helper method within another
class. And the last method is trying to help us develop another way of thinking,
divide the method into two situation: node is None or node is actually another
parent or a leaf, and call the different helper methods depend of the node.
By the end, I felt pretty beneficial
from this lab, if I were not had this lab, I would just put everything in one
class, yet I now kind of really understand why we put different things in different
classes and inherit from each other. :D
No comments:
Post a Comment