From 6a6596cee516ed8df68d61ceed88f6ee8fe32753 Mon Sep 17 00:00:00 2001 From: eson <474420502@qq.com> Date: Sat, 23 Mar 2019 05:08:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dtop=E4=B8=BAnil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- avl/avl_test.go | 4 ++-- avl/iterator.go | 4 +++- lastack/lastack.go | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/avl/avl_test.go b/avl/avl_test.go index e2680d3..07f145b 100644 --- a/avl/avl_test.go +++ b/avl/avl_test.go @@ -80,7 +80,7 @@ func TestIterator(t *testing.T) { // └── 1` iter := avl.Iterator() // root start point - + t.Error(iter.cur, spew.Sdump(iter.tstack)) l := []int{14, 15, 20, 21, 30} for i := 0; iter.Prev(); i++ { @@ -95,7 +95,7 @@ func TestIterator(t *testing.T) { } l = []int{21, 20, 15, 14, 7, 7, 6, 5, 4, 3, 2, 1} - t.Error(iter.cur, iter.tstack) + t.Error(iter.cur, spew.Sdump(iter.tstack)) for i := 0; iter.Next(); i++ { // cur is 30 next is 21 if iter.Value().(int) != l[i] { t.Error(iter.Value()) diff --git a/avl/iterator.go b/avl/iterator.go index a0a834d..d20e993 100644 --- a/avl/iterator.go +++ b/avl/iterator.go @@ -3,6 +3,8 @@ package avl import ( "log" + "github.com/davecgh/go-spew/spew" + "474420502.top/eson/structure/lastack" ) @@ -186,7 +188,7 @@ func (iter *Iterator) curPushNextStack(cur *Node) { next := cur.children[0] // 当前的左然后向右找, 找到最大, 就是最接近cur 并且小于cur的值 if next != nil { - log.Println(iter.tstack) + log.Println(spew.Sdump(iter.tstack)) iter.tstack.Push(next) for next.children[1] != nil { next = next.children[1] diff --git a/lastack/lastack.go b/lastack/lastack.go index 65c2b2c..196dc5a 100644 --- a/lastack/lastack.go +++ b/lastack/lastack.go @@ -62,7 +62,7 @@ func New() *Stack { func (as *Stack) Clear() { as.size = 0 - as.top = nil + as.top = &Node{elements: make([]interface{}, 8, 8), cur: -1} as.cache = nil }