2 ms·
You are absolutely correct. Indeed, it is rather trivial to do so. Pushing onto a stack is equivalent to `s = append(s, obj)`. Checking if the stack is empty i
by agentS 14y ago
You are absolutely correct. Indeed, it is rather trivial to do so.
Pushing onto a stack is equivalent to `s = append(s, obj)`.
Checking if the stack is empty is equivalent to `len(s) == 0`.
Peeking at the top (assuming its non-empty) is equivalent to `top := s[len(s)-1]`.
Popping from the top (assuming its non-empty) is equivalent to `s = s[:len(s)-1]`