mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-10 14:50:46 +00:00
34 lines
517 B
Go
34 lines
517 B
Go
package two
|
|
|
|
type stack struct {
|
|
items []interface{}
|
|
}
|
|
|
|
func newStack() *stack {
|
|
return &stack{}
|
|
}
|
|
|
|
func (s *stack) Push(element interface{}) interface{} {
|
|
s.items = append(s.items, element)
|
|
return element
|
|
}
|
|
|
|
func (s *stack) Pop() interface{} {
|
|
l := len(s.items)
|
|
element := s.items[l-1]
|
|
s.items = s.items[:l-1]
|
|
return element
|
|
}
|
|
|
|
func (s *stack) Peek() interface{} {
|
|
return s.items[len(s.items)-1]
|
|
}
|
|
|
|
func (s *stack) Len() int {
|
|
return len(s.items)
|
|
}
|
|
|
|
func (s *stack) IsEmpty() bool {
|
|
return s.Len() == 0
|
|
}
|