(t, lvl=0)
| 79 | |
| 80 | |
| 81 | def display_tree(t, lvl=0): |
| 82 | prefix = ''.join(['>']*lvl) |
| 83 | if t.word is not None: |
| 84 | print("%s%s %s" % (prefix, t.label, t.word)) |
| 85 | else: |
| 86 | print("%s%s -" % (prefix, t.label)) |
| 87 | # if t.left is None or t.right is None: |
| 88 | # raise Exception("Tree node has no word but left and right child are None") |
| 89 | if t.left: |
| 90 | display_tree(t.left, lvl + 1) |
| 91 | if t.right: |
| 92 | display_tree(t.right, lvl + 1) |
| 93 | |
| 94 | |
| 95 | current_idx = 0 |