修改up的修找对象
This commit is contained in:
parent
137dabe066
commit
226627f03e
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user