Standard List
#include <iostream> #include <list> #include <string> using namespace std; /* * Simple STL linked list demo. */ main() { list<string> li; // Fill the list from input, adding each word to alternate ends. string in; bool putfront = true; while(cin >> in) { if(putfront) li.push_front(in); else li.push_back(in); putfront = !putfront; } cout << "----------------------------------------" << "----------------------------------------" << endl; // Use an iterator to print the list forward. list<string>::iterator i; for(i = li.begin(); i != li.end(); ++i) { cout << *i << " "; } cout << endl; // Now print the list backwards. i = li.end(); while(i != li.begin()) cout << *--i << " "; cout << endl; }