-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
41 lines (32 loc) · 786 Bytes
/
Copy pathexample_test.go
File metadata and controls
41 lines (32 loc) · 786 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package priorityqueue_test
import (
"fmt"
"github.com/azghr/forge/priorityqueue"
)
func ExampleQueue() {
pq := priorityqueue.New[string]()
pq.Push(priorityqueue.Item[string]{Value: "a", Priority: 10})
pq.Push(priorityqueue.Item[string]{Value: "b", Priority: 5})
it, ok := pq.Pop()
fmt.Println(it.Value, ok)
it, ok = pq.Pop()
fmt.Println(it.Value, ok)
_, ok = pq.Pop()
fmt.Println(ok)
// Output:
// b true
// a true
// false
}
func ExampleQueue_maxHeap() {
pq := priorityqueue.New[string](priorityqueue.WithMaxHeap())
pq.Push(priorityqueue.Item[string]{Value: "low", Priority: 1})
pq.Push(priorityqueue.Item[string]{Value: "high", Priority: 10})
it, _ := pq.Pop()
fmt.Println(it.Value)
it, _ = pq.Pop()
fmt.Println(it.Value)
// Output:
// high
// low
}