黑马220
#include
#include
#include
using namespace std;
void test()
{
listl1;
l1.push_back(10);
l1.push_back(20);
l1.push_back(30);
l1.push_back(40);
//l1[0] 不可以使用[]进行访问
//l1.at(0) 不可以使用[]进行访问
//原因是list本质是链表,不是用连续空间存储数据,迭代器也是不支持随机访问的
cout << "第一个元素是" << l1.front() << endl;
cout << "最后一个元素是:" << l1.back() << endl;
//迭代器是不支持随机访问的
list<int>::iterator it = l1.begin();
it++;//支持双向(递增 递减)
it--;
//it+1 不支持随机访问
}
int main()
{
test();
}