listは双方向のリスト。使い方はvectorとあまり変わらない。しかしvectorと違ってランダムアクセスはできず、シーケンシャルアクセスのみ。
push_back() 末尾に要素を追加
push_front() 先頭に要素を追加
pop_back() 最後の要素を削除
pop_front() 先頭の要素を削除
size() 要素数を返す
begin() 最初の要素への反復子を返す
end() 最後の要素の次の位置(末尾)への反復子を返す
insert() 指定した位置へ挿入
erase() 指定した位置から削除
clear() すべての要素を削除
#include <iostream> #include <list> using namespace std; int main() { list<int> l; for(int i=0; i<10; i++) { l.push_back(i); } list<int>::iterator p; p = l.begin(); while( p != l.end() ) { cout << *p << " "; ++p; } } 実行結果 0 1 2 3 4 5 6 7 8 9