-
Notifications
You must be signed in to change notification settings - Fork 14
/
example_linked_test.go
56 lines (42 loc) · 989 Bytes
/
example_linked_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
package queue_test
import (
"fmt"
"github.com/adrianbrad/queue"
)
func ExampleLinked() {
elems := []int{2, 4, 1}
priorityQueue := queue.NewLinked(
elems,
)
containsTwo := priorityQueue.Contains(2)
fmt.Println("Contains 2:", containsTwo)
size := priorityQueue.Size()
fmt.Println("Size:", size)
if err := priorityQueue.Offer(3); err != nil {
fmt.Println("Offer err: ", err)
return
}
empty := priorityQueue.IsEmpty()
fmt.Println("Empty before clear:", empty)
clearElems := priorityQueue.Clear()
fmt.Println("Clear:", clearElems)
empty = priorityQueue.IsEmpty()
fmt.Println("Empty after clear:", empty)
if err := priorityQueue.Offer(5); 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
// Empty before clear: false
// Clear: [2 4 1 3]
// Empty after clear: true
// Get: 5
}