-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreal_main.go
More file actions
42 lines (34 loc) · 960 Bytes
/
real_main.go
File metadata and controls
42 lines (34 loc) · 960 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
42
package main
import (
"fmt"
"io"
"github.com/fgm/container"
"github.com/fgm/container/queue"
"github.com/fgm/container/stack"
)
type Element int
// SizeHint is an indication of the maximum number of elements expected in the
// queue or stack. It is not a hard limit. Implementations may use it or not.
const sizeHint = 100
func realMain(w io.Writer) int {
var e Element = 42
q := queue.NewSliceQueue[Element](sizeHint) // resp. NewListQueue
q.Enqueue(e)
if lq, ok := q.(container.Countable); ok {
fmt.Fprintf(w, "elements in queue: %d\n", lq.Len())
}
for i := 0; i < 2; i++ {
e, ok := q.Dequeue()
fmt.Fprintf(w, "Element: %v, ok: %t\n", e, ok)
}
s := stack.NewSliceStack[Element](sizeHint) // resp. NewListStack
s.Push(e)
if ls, ok := s.(container.Countable); ok {
fmt.Fprintf(w, "elements in stack: %d\n", ls.Len())
}
for i := 0; i < 2; i++ {
e, ok := s.Pop()
fmt.Fprintf(w, "Element: %v, ok: %t\n", e, ok)
}
return 0
}