MCPcopy
hub / github.com/TheAlgorithms/Go / inOrderHelper

Function inOrderHelper

structure/tree/tree.go:66–83  ·  view source on GitHub ↗
(node, nilNode Node[T])

Source from the content-addressed store, hash-verified

64}
65
66func inOrderHelper[T constraints.Ordered](node, nilNode Node[T]) []T {
67 var stack []Node[T]
68 var ret []T
69
70 for node != nilNode || len(stack) > 0 {
71 for node != nilNode {
72 stack = append(stack, node)
73 node = node.Left()
74 }
75
76 node = stack[len(stack)-1]
77 stack = stack[:len(stack)-1]
78 ret = append(ret, node.Key())
79 node = node.Right()
80 }
81
82 return ret
83}
84
85func preOrderRecursive[T constraints.Ordered](n, nilNode Node[T], traversal *[]T) {
86 if n == nilNode {

Callers

nothing calls this directly

Calls 3

LeftMethod · 0.65
KeyMethod · 0.65
RightMethod · 0.65

Tested by

no test coverage detected