From c4577b0cb90dea55e90e971e399bd3c6d41c98e3 Mon Sep 17 00:00:00 2001 From: David Ashby Date: Sun, 25 Jul 2021 20:59:49 -0400 Subject: [PATCH] fix bug in getNode --- datastructures.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/datastructures.go b/datastructures.go index 5c8abb9..59ba36a 100644 --- a/datastructures.go +++ b/datastructures.go @@ -38,18 +38,18 @@ func (sbt *StringyBTreeNode) Right() TreeNode { } func (sbt *StringyBTreeNode) Print(w io.Writer) { + fmt.Fprintf(w, "k: %s v: %v, ", sbt.k, sbt.v) l, lok := sbt.left.(*StringyBTreeNode) r, rok := sbt.right.(*StringyBTreeNode) - fmt.Fprintf(w, "k: %s v: %v, ", sbt.k, sbt.v) if !rok { fmt.Fprint(w, "r: _, ") } else { fmt.Fprintf(w, "r: %s, ", r.k) } if !lok { - fmt.Fprint(w, "l: _, ") + fmt.Fprint(w, "l: _") } else { - fmt.Fprintf(w, "l: %s, ", l.k) + fmt.Fprintf(w, "l: %s", l.k) } fmt.Fprint(w, "\n") if sbt.left != nil { @@ -96,7 +96,10 @@ func (sbt *StringyBTreeNode) getNode(k string) *StringyBTreeNode { return sbt } 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 { return sbt.right.(*StringyBTreeNode).getNode(k)