修复top为nil
This commit is contained in:
parent
b9fa01abdb
commit
6a6596cee5
|
@ -80,7 +80,7 @@ func TestIterator(t *testing.T) {
|
|||
// └── 1`
|
||||
|
||||
iter := avl.Iterator() // root start point
|
||||
|
||||
t.Error(iter.cur, spew.Sdump(iter.tstack))
|
||||
l := []int{14, 15, 20, 21, 30}
|
||||
|
||||
for i := 0; iter.Prev(); i++ {
|
||||
|
@ -95,7 +95,7 @@ func TestIterator(t *testing.T) {
|
|||
}
|
||||
|
||||
l = []int{21, 20, 15, 14, 7, 7, 6, 5, 4, 3, 2, 1}
|
||||
t.Error(iter.cur, iter.tstack)
|
||||
t.Error(iter.cur, spew.Sdump(iter.tstack))
|
||||
for i := 0; iter.Next(); i++ { // cur is 30 next is 21
|
||||
if iter.Value().(int) != l[i] {
|
||||
t.Error(iter.Value())
|
||||
|
|
|
@ -3,6 +3,8 @@ package avl
|
|||
import (
|
||||
"log"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
|
||||
"474420502.top/eson/structure/lastack"
|
||||
)
|
||||
|
||||
|
@ -186,7 +188,7 @@ func (iter *Iterator) curPushNextStack(cur *Node) {
|
|||
next := cur.children[0] // 当前的左然后向右找, 找到最大, 就是最接近cur 并且小于cur的值
|
||||
|
||||
if next != nil {
|
||||
log.Println(iter.tstack)
|
||||
log.Println(spew.Sdump(iter.tstack))
|
||||
iter.tstack.Push(next)
|
||||
for next.children[1] != nil {
|
||||
next = next.children[1]
|
||||
|
|
|
@ -62,7 +62,7 @@ func New() *Stack {
|
|||
|
||||
func (as *Stack) Clear() {
|
||||
as.size = 0
|
||||
as.top = nil
|
||||
as.top = &Node{elements: make([]interface{}, 8, 8), cur: -1}
|
||||
as.cache = nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user