MCPcopy Create free account
hub / github.com/careercup/ctci / Push

Method Push

Go/Chapter 3/Question3_2/Question.go:27–35  ·  view source on GitHub ↗
(value int64)

Source from the content-addressed store, hash-verified

25}
26
27func (s *Stack) Push(value int64) {
28 s.top = &Element{value, s.top}
29 s.size++
30 if len(s.min) == 0 {
31 s.min = append(s.min, value)
32 } else if s.min[len(s.min)-1] > value { // if last elem in slice is greater
33 s.min = append(s.min, value) // add the value to the end of the slice
34 }
35}
36
37// Remove the top element from the stack and return it's value
38// If the stack is empty, return maxInt, error

Callers 6

pushDownFunction · 0.45
sortStackFunction · 0.45
EnQueueMethod · 0.45
DeQueueMethod · 0.45
mainFunction · 0.45
AddMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected