added test and find to binarySearchTree

This commit is contained in:
Acid
2026-06-18 00:15:56 -04:00
parent ab6b370b3a
commit e1a757400a
3 changed files with 262 additions and 1 deletions
+22
View File
@@ -65,3 +65,25 @@ func displayHelper[T NumericTypes](node *Node[T]) {
displayHelper(node.left)
displayHelper(node.right)
}
// Find() => binary search implementation returns a pointer to the node and true if val is found in tree, else returns zero struct and false
func (t BSTree[T]) Find(val T) (*Node[T], bool) {
zero := &Node[T]{}
if t.root == nil {
return zero, false
}
for t.root != nil {
if val == t.root.Data {
return t.root, true
} else if val < t.root.Data {
t.root = t.root.left
} else if val > t.root.Data {
t.root = t.root.right
}
}
fmt.Println("Data not Found")
return zero, false
}