From 226627f03eb900eac98e89a6091585387cbc444b Mon Sep 17 00:00:00 2001 From: huangsimin Date: Wed, 13 Mar 2019 14:45:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9up=E7=9A=84=E4=BF=AE=E6=89=BE?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- avl/avl_test.go | 5 +++-- avl/iterator.go | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/avl/avl_test.go b/avl/avl_test.go index b412a4d..06d92cd 100644 --- a/avl/avl_test.go +++ b/avl/avl_test.go @@ -42,11 +42,12 @@ func TestRotate(t *testing.T) { func TestIterator(t *testing.T) { avl := New(utils.IntComparator) for _, v := range []int{1, 2, 7, 4, 5, 6, 7, 14, 15, 20, 30, 21, 3} { - t.Error(v) + // t.Error(v) avl.Put(v) - t.Error(avl.debugString()) + } t.Error(avl.TraversalDepth(1)) + t.Error(avl.debugString()) iter := avl.Iterator() for iter.Prev() { diff --git a/avl/iterator.go b/avl/iterator.go index a14347c..cf0230f 100644 --- a/avl/iterator.go +++ b/avl/iterator.go @@ -40,7 +40,7 @@ func (iter *Iterator) Next() (result bool) { if iter.tstack.Size() == 0 { if iter.up != nil { iter.tstack.Push(iter.up) - iter.up = iter.getNextUp(iter.cur) + iter.up = iter.getNextUp(iter.up) } else { return false } @@ -62,7 +62,7 @@ func (iter *Iterator) getNextUp(cur *Node) *Node { } cur = cur.parent } - return cur + return nil } func (iter *Iterator) curPushNextStack(cur *Node) { @@ -84,7 +84,7 @@ func (iter *Iterator) getPrevUp(cur *Node) *Node { } cur = cur.parent } - return cur + return nil } func (iter *Iterator) curPushPrevStack(cur *Node) { @@ -116,7 +116,7 @@ func (iter *Iterator) Prev() (result bool) { if iter.tstack.Size() == 0 { if iter.up != nil { iter.tstack.Push(iter.up) - iter.up = iter.getPrevUp(iter.cur) + iter.up = iter.getPrevUp(iter.up) } else { return false }