forked from shellfly/algo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
49 lines (43 loc) · 850 Bytes
/
main.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
/******************************************************************************
* Execution: go run cmd/bag/main.go < input.txt
*
* A generic bag or multiset, implemented using a singly linked list.
*
* % more tobe.txt
* to be or not to - be - - that - - - is
*
* % go run cmd/bag/main.go < tobe.txt
* size of bag = 14
* is
* -
* -
* -
* that
* -
* -
* be
* -
* to
* not
* or
* be
* to
*
******************************************************************************/
package main
import (
"fmt"
"github.com/shellfly/algo/algs4"
"github.com/shellfly/algo/stdin"
)
func main() {
words := stdin.ReadAllStrings()
bag := algs4.NewBag()
for _, word := range words {
bag.Add(word)
}
fmt.Println("size of bag = ", bag.Size())
for _, item := range bag.StringSlice() {
fmt.Println(item)
}
}