MCPcopy Create free account
hub / github.com/arnauddri/algorithms / Search

Method Search

data-structures/binary-tree/bst.go:70–87  ·  view source on GitHub ↗
(i int)

Source from the content-addressed store, hash-verified

68}
69
70func (t *Tree) Search(i int) *Node {
71 h := t.Head
72 n := &Node{Value: i}
73
74 for h != nil {
75 switch h.Compare(n) {
76 case -1:
77 h = h.Right
78 case 1:
79 h = h.Left
80 case 0:
81 return h
82 default:
83 panic("Node not found")
84 }
85 }
86 panic("Node not found")
87}
88
89// returns true if a node with value i was found
90// and deleted and returns false otherwise

Callers 1

TestTreeFunction · 0.95

Calls 1

CompareMethod · 0.80

Tested by 1

TestTreeFunction · 0.76