list
模版原型:
template < class T, class Alloc = allocator > class list;
是一个双向链表
Lists are sequence containers that allow constant time insert and erase operations anywhere within the sequence, and iteration in both directions.
List containers are implemented as doubly-linked lists; Doubly linked lists can store each of the elements they contain in different and unrelated storage locations. The ordering is kept internally by the association to each element of a link to the element preceding it and a link to the element following it.
They are very similar to forward_list: The main difference being that forward_list objects are single-linked lists, and thus they can only be iterated forwards, in exchange for being somewhat smaller and more efficient.
成员
示例
#include <iostream>
#include <list>
using namespace std;
int main ()
{
/**
基本构造函数
*/
list<int> first; // empty list of ints
list<int> second (4,100); // 4 ints with value 100
list<int> third (second.begin(),second.end()); // iterating through second
list<int> fourth (third); // a copy of third
int myints[] = {16,2,77,29};
list<int> fifth (myints, myints + sizeof(myints) / sizeof(int) );
cout << "The contents of fifth are: ";
for (list<int>::iterator it = fifth.begin(); it != fifth.end(); it++){
cout << *it << ' ';
}
cout << endl;
/**
迭代器功能begin,end,rbegin,rend,cbegin,cend,crbegin,crend使用是stl容器中通用的功能,可以参考vector内容
empty 是否为空列表
size 列表尺寸
max_size 当前环境可存档最大元素个数
front,back 返回第一个、最后一个元素的引用
back与end区别: 返回值不同,一个是引用,一个是迭代器。
Returns a reference to the last element in the list container.
Unlike member list::end, which returns an iterator just past this element,
this function returns a direct reference.
*/
//assign Assign new content to container
//Assigns new contents to the list container, replacing its current contents, and //modifying its size accordingly.
return 0;
}