From fafe2feaa4ad68d172f45ffcde44ed3ba276f482 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Thu, 18 Jul 2019 14:57:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E4=B8=AA=E5=AE=8C=E6=95=B4=E7=9A=84re?= =?UTF-8?q?adme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 57 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index ba51d5f..ed825d9 100644 --- a/README.md +++ b/README.md @@ -5,18 +5,47 @@ ## PriorityQueue ``` golang -pq := pqueuekey.New(compare.Int) -pq.Push(1, 1) -pq.Push(4, 4) -pq.Push(5, 5) -pq.Push(6, 6) -pq.Push(2, 2) // pq.Values() = [6 5 4 2 1] -value, _ := pq.Pop() // value = 6 -value, _ = pq.Get(1) // value = 1 pq.Values() = [5 4 2 1] -value, _ = pq.Get(0) // value = nil , Get equal to Seach Key -value, _ = pq.Index(0) // value = 5, compare.Int the order from big to small -values := pq.GetRange(2, 5) // values = [2 4 5] -values = pq.GetRange(5, 2) // values = [5 4 2] -values = pq.GetRange(100, 2) // values = [5 4 2] -values3 := pq.GetAround(5) // values3 = [, 5, 4] +package main + +import ( + "log" + + "github.com/474420502/focus/compare" + pqueuekey "github.com/474420502/focus/priority_queuekey" +) + +func main() { + pq := pqueuekey.New(compare.Int) + pq.Push(1, 1) + pq.Push(4, 4) + pq.Push(5, 5) + pq.Push(6, 6) + pq.Push(2, 2) // pq.Values() = [6 5 4 2 1] + log.Println(pq.Values()) + value, _ := pq.Pop() // value = 6 + log.Println(value) + value, _ = pq.Get(1) // value = 1 pq.Values() = [5 4 2 1] + log.Println(value) + value, _ = pq.Get(0) // value = nil , Get equal to Seach Key + log.Println(value) + value, _ = pq.Index(0) // value = 5, compare.Int the order from big to small + log.Println(value) + values := pq.GetRange(2, 5) // values = [2 4 5] + log.Println(values) + values = pq.GetRange(5, 2) // values = [5 4 2] + log.Println(values) + values = pq.GetRange(100, 2) // values = [5 4 2] + log.Println(values) + values3 := pq.GetAround(5) // values3 = [, 5, 4] + log.Println(values3) + + iter := pq.Iterator() // Next 小到大 + // log.Println(iter.Value()) 直接使用会报错, + iter.Next() + log.Println(iter.Value()) // 起始最大值 5 + + log.Println(iter.Next(), iter.Value()) // 5 + // 大到小 + log.Println(iter.Prev(), iter.Value()) // 4 +} ```