PrintReport is a method that prints a report of the tree Node by node
()
| 119 | // PrintReport is a method that prints a report of the tree |
| 120 | // Node by node |
| 121 | func (t *Tree) PrintReport() { |
| 122 | t.Nodes = make(map[int]struct{}) |
| 123 | if t.Root == nil { |
| 124 | return |
| 125 | } |
| 126 | |
| 127 | queue := make([]Node, 0) |
| 128 | queue = append(queue, t.Root) |
| 129 | |
| 130 | head := 0 |
| 131 | |
| 132 | for head < len(queue) { |
| 133 | current := queue[head] |
| 134 | head++ |
| 135 | |
| 136 | print("ID:", current.GetID()) |
| 137 | print(", Current node:", current.Value()) |
| 138 | |
| 139 | if !current.LeftIsNil() { |
| 140 | print(", Left Child:", current.Left().Value()) |
| 141 | |
| 142 | if !t.isInQueue(current.Left().GetID()) { |
| 143 | queue = append(queue, current.Left()) |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | if !current.RightIsNil() { |
| 148 | print(", Right Child:", current.Right().Value()) |
| 149 | |
| 150 | if !t.isInQueue(current.Right().GetID()) { |
| 151 | queue = append(queue, current.Right()) |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | println() |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | // PrintPyramid is a method that prints the tree as a pyramid |
| 160 | func (t *Tree) PrintPyramid() { |