Pop removes and returns the top element from the stack.
()
| 44 | |
| 45 | // Pop removes and returns the top element from the stack. |
| 46 | func (s *Array[T]) Pop() T { |
| 47 | if s.IsEmpty() { |
| 48 | var zeroValue T |
| 49 | return zeroValue // Stack is empty |
| 50 | } |
| 51 | index := len(s.elements) - 1 |
| 52 | popped := s.elements[index] |
| 53 | s.elements = s.elements[:index] |
| 54 | return popped |
| 55 | } |