func (b *BinaryTree) transplant(old, replacement *node) {
	if old.parent == nil {
		b.root = replacement
	} else if old == old.parent.left {
		old.parent.left = replacement
	} else {
		old.parent.right = replacement
	}
	if replacement != nil {
		replacement.parent = old.parent
	}
	old.parent = nil
	old.left = nil
	old.right = nil
}
Sets the replacement node's parent information to that
of the old node and updates the parent of the old node
to point to the replacement. This also updates pointer
values on the old node to nil. For garbage collection.
package binary
type BinaryTree struct {
	root *node
	size int
}
func New() *BinaryTree {
	return &BinaryTree{size: 0}
}
type node struct {
	parent *node
	left   *node
	right  *node
	value  Comparable
}
type Comparable interface {
	CompareTo(other Comparable) int
}
func walkInOrder(node *node, walked []Comparable) []Comparable {
	if node != nil {
		walked = walkInOrder(node.left, walked)
		walked = append(walked, node.value)
		walked = walkInOrder(node.right, walked)
		return walked
	}
	return nil
}
func (b *BinaryTree) Walk() []Comparable {
	walked := make([]Comparable, 0, b.size)
	return walkInOrder(b.root, walked)
}
func walkPreOrder(node *node, walked []Comparable) []Comparable {
	if node != nil {
		walked = append(walked, node.value)
		walked = walkPreOrder(node.left, walked)
		walked = walkPreOrder(node.right, walked)
		return walked
	}
	return nil
}
func (b *BinaryTree) WalkPreOrder() []Comparable {
	walked := make([]Comparable, 0, b.size)
	return walkPreOrder(b.root, walked)
}
func walkPostOrder(node *node, walked []Comparable) []Comparable {
	if node != nil {
		walked = walkPostOrder(node.left, walked)
		walked = walkPostOrder(node.right, walked)
		walked = append(walked, node.value)
		return walked
	}
	return nil
}
func (b *BinaryTree) WalkPostOrder() []Comparable {
	walked := make([]Comparable, 0, b.size)
	return walkPostOrder(b.root, walked)
}
func (b *BinaryTree) search(target Comparable) *node {
	current := b.root
	for current != nil {
		switch current.value.CompareTo(target) {
		case -1:
			current = current.left
		case 0:
			return current
		case 1:
			current = current.right
		}
	}
	return nil
}
func (b *BinaryTree) Contains(target Comparable) bool {
	return b.search(target) != nil
}
func minimum(startNode *node) *node {
	current := startNode
	for current.left != nil {
		current = current.left
	}
	return current
}
func (b *BinaryTree) Minimum() *Comparable {
	return &minimum(b.root).value
}
func (b *BinaryTree) Maximum() *Comparable {
	current := b.root
	for current.right != nil {
		current = current.right
	}
	rval := current.value
	return &rval
}
func (b *BinaryTree) Successor(target Comparable) *Comparable {
	current := b.search(target)
	if current == nil {
		return nil
	}
	if current.right != nil {
		return &minimum(current.right).value
	}
	if current == b.root {  
		return nil
	}
	parent := current.parent
	for parent != nil && current == parent.right {
		current = parent
		parent = current.parent
	}
	return &current.value
}
func (b *BinaryTree) Insert(value Comparable) {
	newNode := new(node)
	newNode.value = value
	y := (*node)(nil)
	x := b.root
	for x != nil {
		y = x
		if value.CompareTo(x.value) == -1 {  
			x = x.left
		} else {
			x = x.right
		}
	}
	newNode.parent = y
	if newNode.parent == nil {
		b.root = newNode
	} else if newNode.value.CompareTo(y.value) == -1 {
		y.left = newNode
	} else {
		y.right = newNode
	}
	b.size++
}