r""" Create a binary tree with the specified structure: 11 / \ 2 29 / \ / \ 1 7 15 40 \ 35 >>> list(BinaryTree.build_a_tree()) [1, 2, 7, 11, 15, 29, 35, 40]
(cls)
| 107 | |
| 108 | @classmethod |
| 109 | def build_a_tree(cls) -> BinaryTree: |
| 110 | r""" |
| 111 | Create a binary tree with the specified structure: |
| 112 | 11 |
| 113 | / \ |
| 114 | 2 29 |
| 115 | / \ / \ |
| 116 | 1 7 15 40 |
| 117 | \ |
| 118 | 35 |
| 119 | >>> list(BinaryTree.build_a_tree()) |
| 120 | [1, 2, 7, 11, 15, 29, 35, 40] |
| 121 | """ |
| 122 | tree = BinaryTree(Node(11)) |
| 123 | root = tree.root |
| 124 | root.left = Node(2) |
| 125 | root.right = Node(29) |
| 126 | root.left.left = Node(1) |
| 127 | root.left.right = Node(7) |
| 128 | root.right.left = Node(15) |
| 129 | root.right.right = Node(40) |
| 130 | root.right.right.left = Node(35) |
| 131 | return tree |
| 132 | |
| 133 | @classmethod |
| 134 | def build_a_sum_tree(cls) -> BinaryTree: |
no test coverage detected