Pop removes data from the top of the stack.
()
| 37 | |
| 38 | // Pop removes data from the top of the stack. |
| 39 | func (s *Stack) Pop() (*Data, error) { |
| 40 | if len(s.data) == 0 { |
| 41 | return nil, errors.New("stack empty") |
| 42 | } |
| 43 | |
| 44 | // Calculate the top level index. |
| 45 | idx := len(s.data) - 1 |
| 46 | |
| 47 | // Copy the data from that index position. |
| 48 | data := s.data[idx] |
| 49 | |
| 50 | // Remove the top level index from the slice. |
| 51 | s.data = s.data[:idx] |
| 52 | |
| 53 | return data, nil |
| 54 | } |
| 55 | |
| 56 | // Peek provides the data stored on the stack based |
| 57 | // on the level from the bottom. A value of 0 would |