常用的C++ STL

这里写自定义目录标题

常用的C++ STL

常用到的C++ STL,方便查询。

stack

Stack是一种容器适配器,专门设计用于LIFO (last-in first-out)操作,仅从容器的一端插入删除元素(back or top)。

成员类型(c++98)

member typedefinitionnotes
value_typeThe first template parameter (T)Type of the elements
container_typeThe second template parameter (Container)Type of the underlying container
size_typean unsigned integral typeusually the same as size_t

成员函数

函数说明
emptyTest whether container is empty
sizeReturn size
topAccess next element
pushInsert element
popRemove top element
emplace(c++11)Construct and insert element
swap(c++11)Swap contents

queue

Queue 是一种容器适配器,专门设计用于FIFO (first-in first-out) 操作,从容器的一端插入从另一端元素(push from back and pop from front)。

成员类型(c++98)

member typedefinitionnotes
value_typeThe first template parameter (T)Type of the elements
container_typeThe second template parameter (Container)Type of the underlying container
size_typean unsigned integral typeusually the same as size_t

成员函数

函数说明
emptyTest whether container is empty
sizeReturn size
frontAccess next element
backAccess last element
pushInsert element
popRemove next element
emplace(c++11)Construct and insert element
swap(c++11)Swap contents

deque

双端队列(double-ended queue),是具有动态大小的容器序列,可以在两端(前端后端)扩展或收缩。
特定的库可以以不同的形式实现Deque,通常是动态数组。但在任何一种实现,他们都允许通过随机访问迭代器直接访问独立元素,并自动按需处理容量的扩展和收缩。
因此,它提供了与 vector 十分类似的功能,它不仅可以末尾也可以在序列的前端插入和删除元素。但与 vectors 不同的是,deques 不能保证所有元素都存储在连续的位置:通过偏移指针去访问另一个元素会导致未定义的行为。
vectors 和 deque 提供了非常相似的功能,但是,它们内部的工作方式十分不同。vectors 使用单个数组,需要偶尔重新分配以应对数据的增长,deque 的元素可以被分散到不同的存储块,容器保持必要的信息,提供在常数时间内直接访问任何元素(通过 iterators)。因此,deques 更复杂,对于特别长的序列,相对与重新分配内存,deques 能更加有效的增长。

成员类型

member typedefinitionnotes
value_typeThe first template parameter (T)Type of the elements
allocator_typeThe second template parameter (Alloc)defaults to: allocator<value_type>
referenceallocator_type::referencefor the default allocator: value_type&
const_referenceallocator_type::const_referencefor the default allocator: const value_type&
pointerallocator_type::pointerfor the default allocator: value_type*
const_pointerallocator_type::const_pointerfor the default allocator: const value_type*
iteratora random access iterator to value_typeconvertible to const_iterator
const_iteratora random access iterator to const value_type
reverse_iteratorreverse_iterator
const_reverse_iteratorreverse_iterator<const_iterator>
difference_typea signed integral type, identical to: iterator_traits::difference_typeusually the same as ptrdiff_t
size_typean unsigned integral type that can represent any non-negative value of difference_typeusually the same as size_t

成员函数

函数说明
emptyTest whether container is empty
sizeReturn size
max_sizeReturn maximum size
resizeChange size
shrink_to_fit(c++11)Shrink to fit
assignAssign container content
push_backAdd element at the end
push_frontInsert element at beginning
pop_backDelete last element
pop_frontDelete first element
insertInsert elements
eraseErase elements
swapSwap content
clearClear content
emplace(c++11)Construct and insert element
emplace_front(c++11)Construct and insert element at beginning
emplace_back(c++11)Construct and insert element at the end
  • 22
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值