MCPcopy Index your code
hub / github.com/careercup/ctci / Pop

Method Pop

Go/Chapter 3/stack/stack.go:36–44  ·  view source on GitHub ↗

Remove the top element from the stack and return it's value If the stack is empty, return nil

()

Source from the content-addressed store, hash-verified

34// Remove the top element from the stack and return it's value
35// If the stack is empty, return nil
36func (s *Stack) Pop() (int, error) {
37 if s.size > 0 {
38 val := s.top.value
39 s.top = s.top.next
40 s.size--
41 return val, nil
42 }
43 return 0, errorEmptyStack
44}
45
46func (s *Stack) Peek() (int, error) {
47 if s.size > 0 {

Callers 1

StringMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected