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的指針