堆栈实现是否是C++的一部分STL有能力吗?

发布于 2025-02-10 00:27:22 字数 101 浏览 2 评论 0原文

我在大学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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

魄砕の薆 2025-02-17 00:27:22

您在课程中查看的堆栈实现可能有一个限制,但这对于堆栈并不是必需的。 (而且您的课程确实应该教给您。)

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.)

最好是你 2025-02-17 00:27:22

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文