Inserts a node into the BST
(t *Tree, v int)
| 120 | |
| 121 | //Inserts a node into the BST |
| 122 | func insert(t *Tree, v int) *Tree { |
| 123 | if t == nil { |
| 124 | return &Tree{nil, v, nil, t, false} |
| 125 | } |
| 126 | if t.Left == nil && t.Right == nil { |
| 127 | if v < t.Value{ |
| 128 | t.Left = &Tree{nil, v, nil, t, false} |
| 129 | } else { |
| 130 | t.Right = &Tree{nil, v, nil, t, false} |
| 131 | } |
| 132 | return t |
| 133 | } |
| 134 | if v < t.Value { |
| 135 | t.Left = insert(t.Left, v) |
| 136 | return t |
| 137 | } |
| 138 | t.Right = insert(t.Right, v) |
| 139 | return t |
| 140 | } |
| 141 | |
| 142 | func main() { |
| 143 | //t1 := New(100, 1) |