C++ PRIMER 第九章

顺序容器:vector list deque

顺序容器适配器: stack queue priority_quequ(没见过,第一轮不管)

C<T> c; C c(c2); C c(b,e) ///b e 都是迭代器; c(n,t)///只用于顺序容器; C c(n) ///只用于顺序容器

const list<int>::size_type list_size = 64;

list<string> slist(size_type,"eh?");

 支持复制和赋值是容器元素类型的最低要求

迭代器有对于vector 和 deque有专门的运算,没看懂,也没看懂两个迭代器相加减回发生什么情况

 迭代器是的范围是是左闭合区间,是为了可以安全的使用where(first != last){++first;}  eras函数使用之后会有什么影响,这个还是要好好看看

所有的顺序容器都有一个push_back()的函数,包括string

insert(p,t),在迭代器p所知想的元素前面插入之为t的新元素,返回新添加元素的迭代器

只有list和deque可以使用push_front函数

swap不会是迭代器失效

list 可以提供可以任意删除和争价的功能,所以最好还是看看,估计会有用,不能老用vector

容器旋选择建议:

如果希望随即访问:vector 或者 deque

如果要在中间位置插入和删除:list

如果在头尾争价散出,deque

string专题没有看,需要专门找时间,太大,太多,太常用

#include<iostream>
#include<queue>
#include<stack>
using namespace std;

int main()
{
 stack<int> s;
 queue<int> q;

 s.push(1);
 s.push(2);
 s.push(3);

// cout<<s.pop()<<endl; 是错的,pop不能丢东西
 cout<<s.top()<<endl;
 s.pop();
 cout<<s.top()<<endl;
 
 q.push(1);
 q.push(2);
 q.push(3);

// cout<<q.pop()<<endl; 是错的,pop不能丢东西
 cout<<q.front()<<endl;
 cout<<q.back()<<endl;

 q.pop();

 cout<<q.front()<<endl;///也就是说,我们要用的是front
 cout<<q.back()<<endl;
 return 1;
}
berkeleysong
原文地址:https://www.cnblogs.com/berkeleysong/p/3732609.html