容器为模板类

 

  • 顺序容器

vector

deque (双端队列)

list  (双向链表)

forward_list(单向链表)

array (固定大小数组)

string ( 与vector 相似)保存字符, substr(), inset(), assign,append(), repace(), find() 第一次出现, rfind() 最后一次出现。to_string()

 

  • string与vector 将元素保存在连续的内存空间。下标访问快, 但插入删除慢
  • list 和 forword_list 容器中添加和删除操作都很快。不能随机访问
  • deque 

插入:

push_back()

push_front()

insert() 返回值为iterator

删除:

pop_back()

pop_front()

erase(p)

erase(p, e)

clear()

  • 容器适配器

stack: pop(), push(), top()

queue: pop(), front(), back(), top(), push()

priority_queue

 

相关文章:

  • 2022-01-10
  • 2022-12-23
  • 2022-12-23
  • 2021-10-30
  • 2021-09-05
  • 2021-08-04
  • 2021-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-20
  • 2022-12-23
相关资源
相似解决方案