(i int)
| 68 | } |
| 69 | |
| 70 | func (t *Tree) Search(i int) *Node { |
| 71 | h := t.Head |
| 72 | n := &Node{Value: i} |
| 73 | |
| 74 | for h != nil { |
| 75 | switch h.Compare(n) { |
| 76 | case -1: |
| 77 | h = h.Right |
| 78 | case 1: |
| 79 | h = h.Left |
| 80 | case 0: |
| 81 | return h |
| 82 | default: |
| 83 | panic("Node not found") |
| 84 | } |
| 85 | } |
| 86 | panic("Node not found") |
| 87 | } |
| 88 | |
| 89 | // returns true if a node with value i was found |
| 90 | // and deleted and returns false otherwise |