#include <iostream>
#include <list>
using namespace std;

class D {
 typedef list<int> L;
 L* result;
 L::iterator ptr;
 public:
   D() : result(0) {}
   ~D() { delete result; }

   void make_result () {
     result = new L;
     for (int i=0; i < 5; ++ i)
        result->push_back (i);
     ptr = result->begin();
   }

   void prev () { 
      if (result == 0) return;
      if (ptr == result->begin()) ptr = result->end (); 
      --ptr; 
   }

   void next () { 
      if (result == 0) return;
      if (++ptr == result->end()) ptr = result->begin (); 
   }
   void display () {
      if (result == 0) return;
      cout << *ptr << ' ';
   }
};

int main () {
  D d;
  d.display (); // output nothing
  cout << endl;

  d.make_result();
  for (int i=0; i < 10; ++i) {
    d.next();
    d.display();
  }
  cout << endl;

  for (int i=0; i < 10; ++i) {
    d.prev();
    d.display();
  }
  cout << endl;
}