| 1 | // Copyright (c) 2015, Emir Pasic. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package main |
| 6 | |
| 7 | import lls "github.com/emirpasic/gods/v2/stacks/linkedliststack" |
| 8 | |
| 9 | // LinkedListStackExample to demonstrate basic usage of LinkedListStack |
| 10 | func main() { |
| 11 | stack := lls.New[int]() // empty |
| 12 | stack.Push(1) // 1 |
| 13 | stack.Push(2) // 1, 2 |
| 14 | stack.Values() // 2, 1 (LIFO order) |
| 15 | _, _ = stack.Peek() // 2,true |
| 16 | _, _ = stack.Pop() // 2, true |
| 17 | _, _ = stack.Pop() // 1, true |
| 18 | _, _ = stack.Pop() // nil, false (nothing to pop) |
| 19 | stack.Push(1) // 1 |
| 20 | stack.Clear() // empty |
| 21 | stack.Empty() // true |
| 22 | stack.Size() // 0 |
| 23 | } |