day 10b complete

This commit is contained in:
2021-12-10 23:00:22 +00:00
parent 0860573c1e
commit b3be061915
5 changed files with 204 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
package main
type Stack struct {
head *StackNode
}
func (s *Stack) Push(item byte) {
if s.head == nil {
s.head = &StackNode{
char: item,
next: nil,
}
} else {
new := StackNode{
char: item,
next: s.head,
}
s.head = &new
}
}
func (s *Stack) Pop() byte {
node := s.Peek()
s.head = node.next
return node.char
}
func (s *Stack) Peek() (node *StackNode) {
node = s.head
if node == nil {
node = &StackNode{}
}
return
}
type StackNode struct {
char byte
next *StackNode
}