MCPcopy Index your code
hub / github.com/TheAlgorithms/Go / PrintReport

Method PrintReport

project_euler/problem_18/tree.go:121–157  ·  view source on GitHub ↗

PrintReport is a method that prints a report of the tree Node by node

()

Source from the content-addressed store, hash-verified

119// PrintReport is a method that prints a report of the tree
120// Node by node
121func (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
160func (t *Tree) PrintPyramid() {

Callers

nothing calls this directly

Calls 7

isInQueueMethod · 0.95
GetIDMethod · 0.65
ValueMethod · 0.65
LeftIsNilMethod · 0.65
LeftMethod · 0.65
RightIsNilMethod · 0.65
RightMethod · 0.65

Tested by

no test coverage detected