コード例 #1
0
ファイル: xudy.py プロジェクト: xvdy/algo
def prepare_data():
    root = Node(3)
    root.left = Node(9)
    root.right = Node(20)
    root.right.left = Node(15)
    root.right.right = Node(7)

    return root
コード例 #2
0
    def test_tree_with_duplicate_data(self):
        root0 = Node(3)
        root0.left = Node(3)
        root0.left.right = Node(1)
        root1 = Node(3)
        root1.right = Node(1)

        is_subtree_expected = True
        self.assertEqual(is_subtree(root0, root1), is_subtree_expected)
コード例 #3
0
    def test_provided_example_2(self):
        """Can't use other methods as this has a duplicated node data in it"""        
        root0 = Node(26)
        root0.left = Node(10)
        root0.right = Node(3)
        root0.right.right = Node(3)
        root0.left.left = Node(4)
        root0.left.right = Node(6)
        root0.left.right.left = Node(30)
        node_des1 = [(10, 4, "L"), (10, 6, "R"), (4, 30, "R")]
        root1 = TreeMaker.from_node_description(node_des1)

        is_subtree_expected = False
        self.assertEqual(is_subtree(root0, root1), is_subtree_expected)