Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我读到 ADT 堆栈可以使用来实现
数组
一个链表
ADT 列表
但是当我使用堆栈时,我只是调用堆栈库。这些实现堆栈库中的哪个使用?
std::stack是一个容器适配器,它使用一些其他容器作为数据的底层存储。默认为std::deque,但您可以指定另一个序列,例如std::list或std::vector如果您愿意。
std::stack
std::deque
std::list
std::vector
对底层容器的要求非常低——如果有内存,它需要支持 a back(), push_back(), pop_back(), size()and swap()(最后两个并不是真正需要的,除非你使用stack::size()or stack::swap(),这可能并不常见)。
back()
push_back()
pop_back()
size()
swap()
stack::size()
stack::swap()