list.push_back && list.push_front

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章