2015年3月27日星期五

Slog of eighth week

The lecture this week talked about the information of the term test and class binary search node.

class BTNode:     ’’’Binary Tree node.’’’
    def __init__(self, data, left=None, right=None):         ’’’ (BTNode, object, BTNode, BTNode) -> NoneType
        Create BTNode (self) with data         and children left and right.         ’’’         self.data, self.left, self.right = data, left, right


If I want to insert a data in a BTNode, I need to be carful about the condition that the BTNode is none. If it is none, then the function needs to return a new BTNode with the data I want to insert. If the BTNode is not none, I will meet 3 conditions. The data is bigger, smaller than the data in the BTNode or equal to the data in the BTNode. When it is bigger, I let the right side to do the recursion. When it is smaller, I let the left side to do the recursion. When it is the same, I won't do anything.

没有评论:

发表评论