2016-06-27 02:21:09 +00:00
|
|
|
// Copyright (c) 2015, Emir Pasic. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
2015-03-06 16:10:34 +00:00
|
|
|
|
2018-09-19 03:40:24 +00:00
|
|
|
package main
|
2015-03-05 23:43:33 +00:00
|
|
|
|
|
|
|
import "github.com/emirpasic/gods/stacks/arraystack"
|
|
|
|
|
2016-06-24 19:52:16 +00:00
|
|
|
// ArrayStackExample to demonstrate basic usage of ArrayStack
|
2018-09-19 03:40:24 +00:00
|
|
|
func main() {
|
2015-03-05 23:43:33 +00:00
|
|
|
stack := arraystack.New() // empty
|
|
|
|
stack.Push(1) // 1
|
|
|
|
stack.Push(2) // 1, 2
|
2015-03-07 17:05:34 +00:00
|
|
|
stack.Values() // 2, 1 (LIFO order)
|
2015-03-05 23:43:33 +00:00
|
|
|
_, _ = stack.Peek() // 2,true
|
|
|
|
_, _ = stack.Pop() // 2, true
|
|
|
|
_, _ = stack.Pop() // 1, true
|
|
|
|
_, _ = stack.Pop() // nil, false (nothing to pop)
|
|
|
|
stack.Push(1) // 1
|
|
|
|
stack.Clear() // empty
|
|
|
|
stack.Empty() // true
|
|
|
|
stack.Size() // 0
|
|
|
|
}
|