Skip to content

ShahramMebashar/go-binary-search-tree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Binary Search Tree in Go

Simple Binary Search tree implementation in Golan with generics

type BinaryTree[T int | float32] struct {
	Value T
	Left  *BinaryTree[T]
	Right *BinaryTree[T]
}

func insert[T int | float32](node *BinaryTree[T], val T) *BinaryTree[T] {
	if node == nil {
		return &BinaryTree[T]{
			Value: val,
		}
	}
	if val > node.Value {
		node.Right = insert[T](node.Right, val)
	}

	if val < node.Value {
		node.Left = insert[T](node.Left, val)
	}
	return node
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages