#include <iostream>
#include <list>
using namespace std;
int main()
{
list<int> listObject; // create an empty list
int i;
for(i=0; i<10; i++) listObject.push_back(i);
cout << "List printed forwards:\n";
list<int>::iterator p = listObject.begin();
while(p != listObject.end()) {
cout << *p << " ";
p++;
}
cout << "\n\n";
cout << "List printed backwards:\n";
p = listObject.end();
while(p != listObject.begin()) {
p--; // decrement pointer before using
cout << *p << " ";
}
return 0;
}
|