From 9231b5dd30b3c2cf482a3b9c038785d10fe043fd Mon Sep 17 00:00:00 2001 From: majianyu Date: Fri, 25 Jan 2019 21:02:09 +0800 Subject: [PATCH] fixed bst delete --- data-structures/binary-tree/bst.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/data-structures/binary-tree/bst.go b/data-structures/binary-tree/bst.go index da1aa35..fca9586 100644 --- a/data-structures/binary-tree/bst.go +++ b/data-structures/binary-tree/bst.go @@ -1,7 +1,5 @@ package bst -import () - type Node struct { Value int Parent *Node @@ -103,10 +101,13 @@ func (t *Tree) Delete(i int) bool { h = h.Right case 0: if h.Left != nil { + left := h.Left right := h.Right - h.Value = h.Left.Value - h.Left = h.Left.Left - h.Right = h.Left.Right + h.Value = left.Value + h.Left = left.Left + // h.Left Reassigned + //h.Right = h.Left.Right + h.Right = left.Right if right != nil { subTree := &Tree{Head: h}