This commit is contained in:
eson 2019-02-19 01:37:01 +08:00
parent 8c05215122
commit 26ba5a9e0a
2 changed files with 19 additions and 5 deletions

View File

@ -20,9 +20,11 @@ type PriorityQueue struct {
func (pq *PriorityQueue) String() string {
content := ""
iter := pq.avl.Iterator()
iter.End()
for !iter.Last() {
iter.Next()
}
for iter.Prev() {
pl := iter.Value().(*PriorityList)
@ -79,9 +81,8 @@ func (pq *PriorityQueue) Push(value interface{}) {
pq.avl.Put(plsp.head.value, plsp)
log.Println("list:", pl.head.value, pl.String())
log.Println("list:", plsp.head.value, plsp.String())
log.Println("values:", pq.avl.Values())
log.Println("pq:", pq.avl.Values())
log.Println("pq:", pq.String(), "\n----------")
}
}()

View File

@ -99,7 +99,8 @@ func TestAvl(t *testing.T) {
}
iter := avl.Iterator()
iter.Next()
iter.End()
iter.Prev()
t.Error(avl.Values(), iter.Value())
f, ok := avl.Floor(10)
@ -111,6 +112,18 @@ func TestAvl(t *testing.T) {
if ok {
t.Error("Ceiling", f)
}
for _, v := range []int{9, 2, 3, 45, 51, 16, 18, 11} {
avl.Put(v, v)
}
iter = avl.Iterator()
iter.End()
for iter.Prev() {
t.Error(iter.Value())
}
}
func TestHeap(t *testing.T) {