3 ms·
> The standard library also seems to be missing a lot of the most common data types. As far as I can tell, there are no standard stack or queue types. ... How c
by dmbass 14y ago
> The standard library also seems to be missing a lot of the most common data types. As far as I can tell, there are no standard stack or queue types. ... How can a language provide an http server, but no stack type?
I've never really done any Go, but aren't these just different use cases for a Slice? Why would they need their own data type?
- agentS 14y agoYou 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]`
- barrkel 14y agoBecause, given a common interface shared between stacks and queue types, you can turn a depth-first search algorithm into a breadth-first one, simply by changing the parameter from stack to queue.