this is i thing a simplest solution you can do, i hope its self explanatory
type Bin struct {
left, right *Bin
value int
}
func New(value int) *Bin {
return &Bin{value: value}
}
func (b *Bin) Insert(value int) {
if value <= b.value {
if b.left == nil {
b.left = New(value)
} else {
b.left.Insert(value)
}
} else {
if b.right == nil {
b.right = New(value)
} else {
b.right.Insert(value)
}
}
}
1
solved Will a struct be modified when in receiver method it is referred to as pointer?