在c++中,vector是向量类型,可以容纳许多类型的数据,因此也被称为容器。
向量在需要扩展大小的时候,会自动处理它自己的存储需求。
list将元素按顺序储存在链表中.与 向量(vectors)相比, 它允许快速的插入和删除,但是随机访问却比较慢。
List是连续的容器,而vector是非连续的容器,即list将元素存储在连续的存储器中,而vector存储在不连续的存储器中。
List支持双向,并为插入和删除操作提供了一种有效的方法。在列表中遍历速度很慢,因为列表元素是按顺序访问的,而vector支持随机访问。
#include#include using namespace std; int main(int argc, char *argv[]) { list
mylist; list ::iterator i; mylist.push_front(2); mylist.push_front(1); mylist.push_back(3); mylist.push_back(4); cout << "push" << endl; for(i = mylist.begin(); i != mylist.end(); i++) cout << *i << endl; mylist.insert(mylist.begin(), 0); cout << "insert" << endl; for(i = mylist.begin(); i != mylist.end(); i++) cout << *i << endl; mylist.erase(mylist.begin()); cout << "earse" << endl; for(i = mylist.begin(); i != mylist.end(); i++) cout << *i << endl; return 0; }



