Exemplo n.º 1
0
 def create_tree_2():
     """
     A
     +-B
     | +-C
     | \-D
     |   +-K
     |   \-L
     |     \-M
     \-E
       +-F
       | \-G
       \-H
         \-I
           \-J
     :return: TreeNode A
     """
     a = TreeNode("A")
     b = TreeNode("B")
     c = TreeNode("C")
     d = TreeNode("D")
     e = TreeNode("E")
     f = TreeNode("F")
     g = TreeNode("G")
     h = TreeNode("H")
     i = TreeNode("I")
     j = TreeNode("J")
     k = TreeNode("K")
     l = TreeNode("L")
     m = TreeNode("M")
     a.add_node(b)
     a.add_node(e)
     b.add_node(c)
     b.add_node(d)
     d.add_node(k)
     d.add_node(l)
     l.add_node(m)
     e.add_node(f)
     e.add_node(h)
     f.add_node(g)
     h.add_node(i)
     i.add_node(j)
     return a
Exemplo n.º 2
0
 def create_tree_1():
     """
     A
     +-B
     | +-C
     | \-D
     \-E
       +-F
       | \-G
       \-H
         \-I
           \-J
     :return: TreeNode A
     """
     a = TreeNode("A")
     b = TreeNode("B")
     c = TreeNode("C")
     d = TreeNode("D")
     e = TreeNode("E")
     f = TreeNode("F")
     g = TreeNode("G")
     h = TreeNode("H")
     i = TreeNode("I")
     j = TreeNode("J")
     a.add_node(b)
     a.add_node(e)
     b.add_node(c)
     b.add_node(d)
     e.add_node(f)
     e.add_node(h)
     f.add_node(g)
     h.add_node(i)
     i.add_node(j)
     return a