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 }