From 26ba5a9e0a9e49c3fea8252e95a0be3360f292a8 Mon Sep 17 00:00:00 2001 From: eson <474420502@qq.com> Date: Tue, 19 Feb 2019 01:37:01 +0800 Subject: [PATCH] 123 --- priority_queue/priority_queue.go | 9 +++++---- priority_queue/priority_queue_test.go | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/priority_queue/priority_queue.go b/priority_queue/priority_queue.go index 835ede5..5d2897b 100644 --- a/priority_queue/priority_queue.go +++ b/priority_queue/priority_queue.go @@ -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----------") - } }() diff --git a/priority_queue/priority_queue_test.go b/priority_queue/priority_queue_test.go index 681cd22..f2ab7d4 100644 --- a/priority_queue/priority_queue_test.go +++ b/priority_queue/priority_queue_test.go @@ -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) {