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 }