fix bug in getNode

This commit is contained in:
David 2021-07-25 20:59:49 -04:00
parent f9d933e33c
commit c4577b0cb9

View File

@ -38,18 +38,18 @@ func (sbt *StringyBTreeNode) Right() TreeNode {
} }
func (sbt *StringyBTreeNode) Print(w io.Writer) { func (sbt *StringyBTreeNode) Print(w io.Writer) {
fmt.Fprintf(w, "k: %s v: %v, ", sbt.k, sbt.v)
l, lok := sbt.left.(*StringyBTreeNode) l, lok := sbt.left.(*StringyBTreeNode)
r, rok := sbt.right.(*StringyBTreeNode) r, rok := sbt.right.(*StringyBTreeNode)
fmt.Fprintf(w, "k: %s v: %v, ", sbt.k, sbt.v)
if !rok { if !rok {
fmt.Fprint(w, "r: _, ") fmt.Fprint(w, "r: _, ")
} else { } else {
fmt.Fprintf(w, "r: %s, ", r.k) fmt.Fprintf(w, "r: %s, ", r.k)
} }
if !lok { if !lok {
fmt.Fprint(w, "l: _, ") fmt.Fprint(w, "l: _")
} else { } else {
fmt.Fprintf(w, "l: %s, ", l.k) fmt.Fprintf(w, "l: %s", l.k)
} }
fmt.Fprint(w, "\n") fmt.Fprint(w, "\n")
if sbt.left != nil { if sbt.left != nil {
@ -96,7 +96,10 @@ func (sbt *StringyBTreeNode) getNode(k string) *StringyBTreeNode {
return sbt return sbt
} }
if sbt.left != nil { if sbt.left != nil {
return sbt.left.(*StringyBTreeNode).getNode(k) r := sbt.left.(*StringyBTreeNode).getNode(k)
if r != nil {
return r
}
} }
if sbt.right != nil { if sbt.right != nil {
return sbt.right.(*StringyBTreeNode).getNode(k) return sbt.right.(*StringyBTreeNode).getNode(k)