summaryrefslogtreecommitdiff
path: root/stack.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-01-09 20:29:32 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-01-09 20:29:32 +0100
commit876d05d5764485a42c9dd0f87c242dc8f355523a (patch)
tree9ec013d357a350e86561a5ffe219cbe598826fe7 /stack.go
parent9bc1a2b8375f067dfb49a8c0ce5411510a338e05 (diff)
Add more helper
Diffstat (limited to 'stack.go')
-rw-r--r--stack.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/stack.go b/stack.go
index f5260ad..d4cf900 100644
--- a/stack.go
+++ b/stack.go
@@ -22,3 +22,21 @@ func (s *Stack) Pop() (v interface{}, ok bool) {
}
return v, ok
}
+
+// Peek returns top value from Stack
+func (s *Stack) Peek() interface{} {
+ return (*s)[len(*s) - 1]
+}
+
+// Depth returns actual size of Stack
+func (s *Stack) Depth() int {
+ return len(*s)
+}
+
+// Swap swapes to top values
+func (s *Stack) Swap() {
+ size := len(*s)
+ if size >= 2 {
+ (*s)[size-1], (*s)[size-2] = (*s)[size-2], (*s)[size-1]
+ }
+}