diff options
author | xuri <xuri.me@gmail.com> | 2020-05-03 18:44:43 +0800 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2020-05-03 18:44:43 +0800 |
commit | 48fc4c08a2a80f7826d20bf3fd5a018f8e6f3185 (patch) | |
tree | fb5b635720a3289a070785b4687560974d32706f /lib.go | |
parent | 2285d4dc718fb8b96c3b2291c63b39c57468b0b9 (diff) |
init formula calculation engine, ref #65 and #599
Diffstat (limited to 'lib.go')
-rw-r--r-- | lib.go | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -12,6 +12,7 @@ package excelize import ( "archive/zip" "bytes" + "container/list" "fmt" "io" "log" @@ -305,3 +306,48 @@ func genSheetPasswd(plaintext string) string { password ^= 0xCE4B return strings.ToUpper(strconv.FormatInt(password, 16)) } + +// Stack defined an abstract data type that serves as a collection of elements. +type Stack struct { + list *list.List +} + +// NewStack create a new stack. +func NewStack() *Stack { + list := list.New() + return &Stack{list} +} + +// Push a value onto the top of the stack. +func (stack *Stack) Push(value interface{}) { + stack.list.PushBack(value) +} + +// Pop the top item of the stack and return it. +func (stack *Stack) Pop() interface{} { + e := stack.list.Back() + if e != nil { + stack.list.Remove(e) + return e.Value + } + return nil +} + +// Peek view the top item on the stack. +func (stack *Stack) Peek() interface{} { + e := stack.list.Back() + if e != nil { + return e.Value + } + return nil +} + +// Len return the number of items in the stack. +func (stack *Stack) Len() int { + return stack.list.Len() +} + +// Empty the stack. +func (stack *Stack) Empty() bool { + return stack.list.Len() == 0 +} |