diff options
author | Julien Dessaux | 2021-11-12 15:26:16 +0100 |
---|---|---|
committer | Julien Dessaux | 2021-11-12 15:28:09 +0100 |
commit | c913c2ae46fd81a3274ef16c64c78ea2ed421de8 (patch) | |
tree | c454e21bfe42080fae433eae402b9f3a1c68783a /pkg/pointer/stack.go | |
parent | Fixed tricky field loading bug (diff) | |
download | gofunge98-c913c2ae46fd81a3274ef16c64c78ea2ed421de8.tar.gz gofunge98-c913c2ae46fd81a3274ef16c64c78ea2ed421de8.tar.bz2 gofunge98-c913c2ae46fd81a3274ef16c64c78ea2ed421de8.zip |
Refactoring : isolate stack manipulation into their own package
Diffstat (limited to '')
-rw-r--r-- | pkg/pointer/stack.go | 53 |
1 files changed, 6 insertions, 47 deletions
diff --git a/pkg/pointer/stack.go b/pkg/pointer/stack.go index ba51c7c..b08b354 100644 --- a/pkg/pointer/stack.go +++ b/pkg/pointer/stack.go @@ -1,54 +1,13 @@ package pointer -type Stack struct { - size int - height int - data []int - next *Stack // Pointer to the next element in the stack stack +func (ss *StackStack) Pop() int { + return ss.head.Pop() } -func NewStack() *Stack { - return &Stack{ - size: 32, - height: 0, - data: make([]int, 32), - next: nil, - } +func (ss *StackStack) Push(v int) { + ss.head.Push(v) } -func (s *Stack) Clear() { - s.height = 0 -} - -func (s *Stack) Duplicate() { - if s.height > 0 { - s.Push(s.data[s.height-1]) - } else { - s.Push(0) - s.Push(0) - } -} - -func (s *Stack) Pop() int { - if s.height > 0 { - s.height-- - return s.data[s.height] - } - return 0 -} - -func (s *Stack) Push(value int) { - if s.height >= s.size { - s.size += 32 - s.data = append(s.data, make([]int, 32)...) - } - s.data[s.height] = value - s.height++ -} - -func (s *Stack) Swap() { - a := s.Pop() - b := s.Pop() - s.Push(a) - s.Push(b) +func (s *StackStack) YCommandPick(n int, h int) { + s.head.YCommandPick(n, h) } |