From c913c2ae46fd81a3274ef16c64c78ea2ed421de8 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Fri, 12 Nov 2021 15:26:16 +0100 Subject: Refactoring : isolate stack manipulation into their own package --- pkg/pointer/stack.go | 53 ++++++---------------------------------------------- 1 file changed, 6 insertions(+), 47 deletions(-) (limited to 'pkg/pointer/stack.go') 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) } -- cgit v1.2.3