list.push_back在链表的最后插入
list.push_front在链表的首位插入
#include<iostream>
#include<list>
using namespace std;
int main() {
list <int> a;
list <int>::iterator Iter;
a.push_back(10);
a.push_back(20);
a.push_front(30);
a.push_front(40);
for (Iter = a.begin(); Iter != a.end(); Iter++) {
cout << *Iter << endl;
}
return 1;
}
结果:
其中:
a.begin()指向容器中最开始数据的位置的指针
a.end()指向容器中最后一个数据的位置+1的指针