diff options
author | Unknwon <u@gogs.io> | 2017-02-09 19:48:13 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2017-02-09 19:48:13 -0500 |
commit | 2fd69f13d9599a6c58b47225565163fd7d87889f (patch) | |
tree | fd19e868e1c2e95a5fb83a268f6e393669d6ee79 /vendor/github.com/sergi/go-diff/diffmatchpatch/stack.go | |
parent | eb66060cd7b9bce996b1d75ae80ce1ef31d5ce62 (diff) |
vendor: check in vendors
Bye bye glide...
Diffstat (limited to 'vendor/github.com/sergi/go-diff/diffmatchpatch/stack.go')
-rw-r--r-- | vendor/github.com/sergi/go-diff/diffmatchpatch/stack.go | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/vendor/github.com/sergi/go-diff/diffmatchpatch/stack.go b/vendor/github.com/sergi/go-diff/diffmatchpatch/stack.go new file mode 100644 index 00000000..d28ae459 --- /dev/null +++ b/vendor/github.com/sergi/go-diff/diffmatchpatch/stack.go @@ -0,0 +1,66 @@ +package diffmatchpatch + +import ( + "fmt" +) + +type Stack struct { + top *Element + size int +} + +type Element struct { + value interface{} + next *Element +} + +// Len returns the stack's length +func (s *Stack) Len() int { + return s.size +} + +// Push appends a new element onto the stack +func (s *Stack) Push(value interface{}) { + s.top = &Element{value, s.top} + s.size++ +} + +// Pop removes the top element from the stack and return its value +// If the stack is empty, return nil +func (s *Stack) Pop() (value interface{}) { + if s.size > 0 { + value, s.top = s.top.value, s.top.next + s.size-- + return + } + return nil +} + +// Peek returns the value of the element on the top of the stack +// but don't remove it. If the stack is empty, return nil +func (s *Stack) Peek() (value interface{}) { + if s.size > 0 { + value = s.top.value + return + } + return -1 +} + +// Clear empties the stack +func (s *Stack) Clear() { + s.top = nil + s.size = 0 +} + +func main() { + stack := new(Stack) + + stack.Push("Things") + stack.Push("and") + stack.Push("Stuff") + + for stack.Len() > 0 { + fmt.Printf("%s ", stack.Pop().(string)) + } + fmt.Println() +} |