#C++ Stacks Understanding

19 messages · Page 1 of 1 (latest)

reef sail
#

I don't understand what's the need of container parameter for Stacks, because even if I change it how would it affect the Stack ?
My guess on it is that the Stack stores the values it has in a Vector causing it to match the speed of a Vector, but that doesn't make sense in a lot of ways.

real fogBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

viscid basalt
reef sail
viscid basalt
#

I mean std::stack behaves like a stack? it's a LIFO data structure

reef sail
viscid basalt
#

so yeah, thats a bit of a complex awnser, std::stack is essentially an interface for LIFO behavior but it can be implemented in any data structure as long as it provides a set of functions

#

what gives it more flexibility

reef sail
#

Is that the surface level knowledge ?

viscid basalt
#

honestly most of the time you never touch that parameter

#

the std::decue<t> is plenty in most cases

reef sail
#

or cases I might have to change the parameter ?

viscid basalt
#

honestly you would change the underlying type when you want different behaviral patterns from your types, meaby you have a custom allocator you can now provide your own type that uses your custom allocator but have a nice and simple std::stack interface