summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-03-24 01:20:30 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-03-24 01:20:30 +0100
commitac7df7d646ce070c75329d834c0f1a0302602a36 (patch)
treee26ae2360ea8b4fdfc850f4a6208351360bcd7d4
parente1b6726f351c911974e2717e3bf7accd0e18259e (diff)
Value type
-rw-r--r--stack.go21
1 files changed, 11 insertions, 10 deletions
diff --git a/stack.go b/stack.go
index 3546588..49a59da 100644
--- a/stack.go
+++ b/stack.go
@@ -2,7 +2,8 @@
package stack
// Stack contains a generic value
-type Stack []interface{}
+type Value interface{}
+type Stack []Value
// NewStack returns a new Stack
func NewStack() Stack {
@@ -10,31 +11,31 @@ func NewStack() Stack {
}
// Push generic value into Stack
-func (s *Stack) Push(v interface{}) {
+func (s *Stack) Push(v Value) {
*s = append(*s, v)
}
// Pop generic value from Stack
-func (s *Stack) Pop() (v interface{}) {
- if size := len(*s); size >= 1 {
+func (s *Stack) Pop() (v Value) {
+ if size := len(*s); size > 0 {
v, *s = (*s)[size-1], (*s)[:size-1]
}
return v
}
// Peek returns top value from Stack
-func (s Stack) Peek() interface{} {
+func (s Stack) Peek() Value {
return s[len(s)-1]
}
-// Depth returns actual size of Stack
-func (s Stack) Depth() int {
- return len(s)
-}
-
// Swap swapes two top values
func (s Stack) Swap() {
if size := len(s); size >= 2 {
s[size-1], s[size-2] = s[size-2], s[size-1]
}
}
+
+// Depth returns actual size of Stack
+func (s Stack) Depth() int {
+ return len(s)
+}