#include <stdio.h>
#include <list>
using namespace std;
int main()
{
list<int> lst;
list<int>::iterator p;
int i;
for(i = 1; i < 6; i++)
lst.push_back(i);
for(p = lst.begin(); p != lst.end(); p++)
printf("%d ", *p);
putchar('\n');
for(i = 1; i < 6; i++)
lst.push_front(i);
for(p = lst.begin(); p != lst.end(); p++)
printf("%d ", *p);
putchar('\n');
for(p = lst.begin(); p != lst.end(); p++)
lst.insert(p, 0);
for(p = lst.begin(); p != lst.end(); p++)
printf("%d ", *p);
putchar('\n');
return 0;
}
実行結果
1 2 3 4 5
5 4 3 2 1 1 2 3 4 5
0 5 0 4 0 3 0 2 0 1 0 1 0 2 0 3 0 4 0 5