堆栈实现是否是C++的一部分STL有能力吗?
我在大学DSA课程中获悉,堆栈的初始化,其能力限制了它可以包含的元素数量。但是,当我使用STL创建堆栈时,您不必定义容量。是否涉及容量,或者不适用于STL实施?堆栈甚至真的需要容量吗?
I learned in my college DSA course that a stack is initialized with a capacity that limits the number of elements it can contain. But when I create a stack using the STL, you don't have to define a capacity. Is there a capacity involved, or does it not apply in the STL implementation? Do stacks even really need a capacity?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在课程中查看的堆栈实现可能有一个限制,但这对于堆栈并不是必需的。 (而且您的课程确实应该教给您。)
C ++标准库 stack 只是任何支持必要操作的基础藏品的适配器,因此是否有限的容量取决于该基础类型。
(默认值为
std :: Deque
。The stack implementation you looked at in your course may have had a limit, but that's not essential to being a stack. (And your course really should have taught you this.)
The C++ standard library stack is just an adapter for any underlying collection that supports the necessary operations, so whether it has a limited capacity or not depends on that underlying type.
(The default is
std::deque
.)STL中的堆栈是一种容器适配器,因此是否定义容量将取决于您使用过的基础容器的类型(矢量,Deque(默认)或列表)。
还有一件事,这不应与尺寸有限的堆栈内存混淆。
stacks in STL are a type of container adapter, so whether to define the capacity will depend on the type of underlying container you have used(vector, deque(default), or list).
one more thing, this should not be confused with the stack memory, which has a limited size.