diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2023-07-29 10:37:40 -0230 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2023-07-29 10:37:40 -0230 |
| commit | 0e1cd2b6a328887c1a630eae0b34366a607bb1b8 (patch) | |
| tree | 70825addc206c7b7e7fae33bbc0f86ab24534ee8 /stack.go | |
| parent | 5b81647c27af77be3d35e10cb53cad1897a7f392 (diff) | |
| download | pfc-0e1cd2b6a328887c1a630eae0b34366a607bb1b8.zip | |
refactor
Diffstat (limited to 'stack.go')
| -rw-r--r-- | stack.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/stack.go b/stack.go new file mode 100644 index 0000000..182d418 --- /dev/null +++ b/stack.go @@ -0,0 +1,16 @@ +package main + +type Stack []float64 + +func (s *Stack) push(v float64) { + *s = append(*s, v) +} + +func (s *Stack) pop() *float64 { + if len(*s) > 0 { + v := (*s)[len(*s)-1] + *s = (*s)[:len(*s)-1] + return &v + } + return nil +} |