码迷,mamicode.com
首页 > 编程语言 > 详细

C++ 中容器

时间:2017-08-24 00:09:25      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:war   lis   空间   app   双端队列   stack   back   随机   适配   

容器为模板类

 

  • 顺序容器

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

 

C++ 中容器

标签:war   lis   空间   app   双端队列   stack   back   随机   适配   

原文地址:http://www.cnblogs.com/fanhaha/p/7420775.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!