-
Notifications
You must be signed in to change notification settings - Fork 14
/
example_circular_test.go
79 lines (59 loc) · 1.24 KB
/
example_circular_test.go
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package queue_test
import (
"fmt"
"github.com/adrianbrad/queue"
)
func ExampleCircular() {
elems := []int{1, 2, 3}
const capacity = 4
priorityQueue := queue.NewCircular(
elems,
capacity,
)
containsTwo := priorityQueue.Contains(2)
fmt.Println("Contains 2:", containsTwo)
size := priorityQueue.Size()
fmt.Println("Size:", size)
if err := priorityQueue.Offer(4); err != nil {
fmt.Println("Offer err: ", err)
return
}
nextElem, err := priorityQueue.Peek()
if err != nil {
fmt.Println("Peek err: ", err)
return
}
fmt.Println("Peek:", nextElem)
if err := priorityQueue.Offer(5); err != nil {
fmt.Println("Offer err: ", err)
return
}
fmt.Println("Offered 5")
if err := priorityQueue.Offer(6); err != nil {
fmt.Println("Offer err: ", err)
return
}
fmt.Println("Offered 6")
clearElems := priorityQueue.Clear()
fmt.Println("Clear:", clearElems)
fmt.Println("Offered 7")
if err := priorityQueue.Offer(7); err != nil {
fmt.Println("Offer err: ", err)
return
}
elem, err := priorityQueue.Get()
if err != nil {
fmt.Println("Get err: ", err)
return
}
fmt.Println("Get:", elem)
// Output:
// Contains 2: true
// Size: 3
// Peek: 1
// Offered 5
// Offered 6
// Clear: [5 6 3 4]
// Offered 7
// Get: 7
}