forked from PacktPublishing/Mastering-Go-Second-Edition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconList.go
45 lines (35 loc) · 736 Bytes
/
conList.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
package main
import (
"container/list"
"fmt"
"strconv"
)
func printList(l *list.List) {
for t := l.Back(); t != nil; t = t.Prev() {
fmt.Print(t.Value, " ")
}
fmt.Println()
for t := l.Front(); t != nil; t = t.Next() {
fmt.Print(t.Value, " ")
}
fmt.Println()
}
func main() {
values := list.New()
e1 := values.PushBack("One")
e2 := values.PushBack("Two")
values.PushFront("Three")
values.InsertBefore("Four", e1)
values.InsertAfter("Five", e2)
values.Remove(e2)
values.Remove(e2)
values.InsertAfter("FiveFive", e2)
values.PushBackList(values)
printList(values)
values.Init()
fmt.Printf("After Init(): %v\n", values)
for i := 0; i < 20; i++ {
values.PushFront(strconv.Itoa(i))
}
printList(values)
}