#include <iostream>
#ifdef __BORLANDC__
#else
  using namespace std;
#endif

class Lista
  {
   private:
   static Lista *Pierwszy,*Ostatni;
   Lista *Nastepny,*Poprzedni;
   protected:
   virtual void Cout(ostream &S)const;
   public:
   Lista();
   virtual ~Lista();
   static void drukuj(ostream &S);
   friend ostream &operator<<(ostream &s,const Lista &L);
  };
Lista *Lista::Pierwszy=0,*Lista::Ostatni=0;

void Lista::Cout(ostream &S)const
  {
   S<<(void*)this;
  }

ostream &operator<<(ostream &s,const Lista &L)
  {
   L.Cout(s);
   return(s);
  }

Lista::Lista()
  {
   Poprzedni=0;
   Nastepny=Pierwszy;
   if(Pierwszy) Pierwszy->Poprzedni=this;
   else         Ostatni=this;
   Pierwszy=this;
  }

Lista::~Lista()
  {
   if(Poprzedni) Poprzedni->Nastepny=Nastepny;
   else          Pierwszy=Nastepny;
   if(Nastepny)  Nastepny->Poprzedni=Poprzedni;
   else          Ostatni=Poprzedni;
  }

void Lista::drukuj(ostream &S)
  {
   for(Lista *i=Lista::Pierwszy;i;i=i->Nastepny)
     {
      S<<*i<<endl;
     }
  }

class Punkt:public Lista
  {
   protected:
   virtual void Cout(ostream &S)const;
   public:
   double x,y;
   Punkt():x(0),y(0) {}
   Punkt(double x,double y):x(x),y(y) {}
  };

void Punkt::Cout(ostream &S)const
  {
   S<<'('<<x<<','<<y<<')';
  }


int main()
  {
   Punkt P(3,4);
     {
      Lista a;
      Lista *b=new Lista;
        {
         Lista c;

         Lista::drukuj(cout);

         delete b;

         cout<<endl;
         Lista::drukuj(cout);
        }
      cout<<endl;
      Lista::drukuj(cout);
     }
   cout<<endl;
   Lista::drukuj(cout);
   return(0);
  }
