-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
104 lines (65 loc) · 1.24 KB
/
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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Run examples here
package main
import (
"fmt"
)
func main() {
container := Container{}
stack := container.NewContainer()
stack.Push(5)
stack.Push(6)
stack.Push(7)
stack.Push("*")
stack.Push("+")
stack.Push(1)
stack.Push("-")
fmt.Println(PostFixCalculator(container))
}
func stackExample() {
container := Container{}
stack := container.NewContainer()
stack.Push(6)
// Prints 6
fmt.Println(stack.Peek())
stack.Push(19)
stack.Push(20)
// Print 20
fmt.Println(stack.Peek())
stack.Pop()
// Print 19
fmt.Println(stack.Peek())
}
func linkedListExample() {
newList := LinkedList{}
newList.Append(&Node{Value: 10})
fmt.Println(newList.Tail.Value)
newList.Append(&Node{Value: 12})
fmt.Println(newList.Head.Value)
}
func nodeExample() {
firstNode := Node{Value: 3}
secondNode := Node{Value: 5}
thirdNode := Node{Value: 7}
fourthNode := Node{Value: 9}
firstNode.Next = &secondNode
secondNode.Next = &thirdNode
thirdNode.Next = &fourthNode
printList(firstNode)
}
func printList(node Node) {
defer func() {
if recover() != nil {
fmt.Println("Dead")
}
}()
for node.Value != 0 {
_, err := fmt.Println(node)
if err != nil {
break
}
if node.Next == nil {
break
}
node = *node.Next
}
}