(x *BSNode[T], val T)
| 164 | } |
| 165 | |
| 166 | func (t *BinarySearch[T]) pushHelper(x *BSNode[T], val T) { |
| 167 | y := t._NIL |
| 168 | for x != t._NIL { |
| 169 | y = x |
| 170 | switch { |
| 171 | case val < x.Key(): |
| 172 | x = x.left |
| 173 | case val > x.Key(): |
| 174 | x = x.right |
| 175 | default: |
| 176 | return |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | z := &BSNode[T]{ |
| 181 | key: val, |
| 182 | left: t._NIL, |
| 183 | right: t._NIL, |
| 184 | parent: y, |
| 185 | } |
| 186 | if y == t._NIL { |
| 187 | t.Root = z |
| 188 | } else if val < y.key { |
| 189 | y.left = z |
| 190 | } else { |
| 191 | y.right = z |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | func (t *BinarySearch[T]) deleteHelper(z *BSNode[T]) { |
| 196 | switch { |