pop remove last item as first output
()
| 34 | |
| 35 | // pop remove last item as first output |
| 36 | func (ll *Stack) Pop() any { |
| 37 | result := ll.top.Val |
| 38 | if ll.top.Next == nil { |
| 39 | ll.top = nil |
| 40 | } else { |
| 41 | ll.top.Val, ll.top.Next = ll.top.Next.Val, ll.top.Next.Next |
| 42 | } |
| 43 | |
| 44 | ll.length-- |
| 45 | return result |
| 46 | } |
| 47 | |
| 48 | // isEmpty to check our array is empty or not |
| 49 | func (ll *Stack) IsEmpty() bool { |
no outgoing calls