// Insert to insert a key-payload pair into tree
Insert to insert a key-payload pair into tree
// Insert to insert a key - payload pair into tree
func (b *BinarySearchTree) Insert(key int, payload interface{}) {
	newNode := &treeNode{}
	newNode.key = key
	newNode.payload = payload
	if b.root == nil {
		b.root = newNode
		b.count++
		return
	}
	node := b.root
	for node != nil {
		if newNode.key < node.key {
			if node.leftChild == nil {
				node.leftChild = newNode
				newNode.parent = node
				b.count++
				return
			}
			node = node.leftChild
		} else { 
			if node.rightChild == nil {
				node.rightChild = newNode
				newNode.parent = node
				b.count++
				return
			}
			node = node.rightChild
		}
	}
}
func ( b * BinarySearchTree ) Insert ( key int , payload interface { } ) { newNode := & treeNode { } newNode . key = key newNode . payload = payload if b . root == nil { b . root = newNode b . count ++ return } node := b . root for node != nil { if newNode . key < node . key { if node . leftChild == nil { node . leftChild = newNode newNode . parent = node b . count ++ return } node = node . leftChild } else { if node . rightChild == nil { node . rightChild = newNode newNode . parent = node b . count ++ return } node = node . rightChild } } }
Insert to insert a key-payload pair into tree
Insert to insert a key - payload pair into tree
// >= can allow multiple nodes have same key