TODO: 修改后测试不正确

This commit is contained in:
huangsimin 2019-03-13 14:34:20 +08:00
parent 2333e08152
commit 137dabe066

View File

@ -31,17 +31,7 @@ func (iter *Iterator) Next() (result bool) {
if iter.cur != nil {
iter.tstack.Clear()
iter.curPushNextStack(iter.cur)
iter.up = iter.cur
for iter.up != nil {
if iter.up.child == 1 {
iter.up = iter.up.parent
break
} else {
iter.up = iter.up.parent
}
}
iter.up = iter.getNextUp(iter.cur)
}
}
iter.dir = 1
@ -50,14 +40,7 @@ func (iter *Iterator) Next() (result bool) {
if iter.tstack.Size() == 0 {
if iter.up != nil {
iter.tstack.Push(iter.up)
for iter.up != nil {
if iter.up.child == 1 {
iter.up = iter.up.parent
break
} else {
iter.up = iter.up.parent
}
}
iter.up = iter.getNextUp(iter.cur)
} else {
return false
}
@ -72,6 +55,16 @@ func (iter *Iterator) Next() (result bool) {
return false
}
func (iter *Iterator) getNextUp(cur *Node) *Node {
for cur != nil {
if cur.child == 1 { // next 在 降序 小值. 如果child在右边, parent 比 child 小, parent才有效, 符合降序
return cur.parent
}
cur = cur.parent
}
return cur
}
func (iter *Iterator) curPushNextStack(cur *Node) {
next := cur.children[0]
@ -84,6 +77,16 @@ func (iter *Iterator) curPushNextStack(cur *Node) {
}
}
func (iter *Iterator) getPrevUp(cur *Node) *Node {
for cur != nil {
if cur.child == 0 { // Prev 在 降序 大值. 如果child在左边, parent 比 child 大, parent才有效 , 符合降序
return cur.parent
}
cur = cur.parent
}
return cur
}
func (iter *Iterator) curPushPrevStack(cur *Node) {
prev := cur.children[1]
@ -104,16 +107,7 @@ func (iter *Iterator) Prev() (result bool) {
if iter.cur != nil {
iter.tstack.Clear()
iter.curPushPrevStack(iter.cur)
iter.up = iter.cur
for iter.up != nil {
if iter.up.child == 0 {
iter.up = iter.up.parent
break
} else {
iter.up = iter.up.parent
}
}
iter.up = iter.getPrevUp(iter.cur)
}
}
iter.dir = -1
@ -122,14 +116,7 @@ func (iter *Iterator) Prev() (result bool) {
if iter.tstack.Size() == 0 {
if iter.up != nil {
iter.tstack.Push(iter.up)
for iter.up != nil {
if iter.up.child == 0 {
iter.up = iter.up.parent
break
} else {
iter.up = iter.up.parent
}
}
iter.up = iter.getPrevUp(iter.cur)
} else {
return false
}