修改up的修找对象

This commit is contained in:
huangsimin 2019-03-13 14:45:27 +08:00
parent 137dabe066
commit 226627f03e
2 changed files with 7 additions and 6 deletions

View File

@ -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() {

View File

@ -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
}