#include<fstream.h>
ifstream f("date.in");
ofstream g("date.out");
struct nodd{int info;
nodd *prec,*urm;
};
nodd *prim;
void adaugs(nodd *&prim,int x)
{nodd *u=prim;
if(prim)
{while(u->urm) u=u->urm;
nodd *nou=new nodd;
nou->info=x;
u->urm=nou;
nou->prec=u;
nou->urm=0;
}
else {prim=new nodd;
prim->info=x;
prim->urm=0;
prim->prec=0;
}
}
void creare(nodd *&prim)
{int x;
while(f>>x) adaugs(prim,x);
}
void afis(nodd *prim)
{nodd *p=prim;
while(p->urm) {g<<p->info<<" ";
p=p->urm;
}
g<<p->info<<" ";
g<<endl;
}
void mutapu(nodd *&prim)
{nodd *u=prim;
while(u->urm) u=u->urm;
u->urm=prim;
prim->prec=u;
prim=prim->urm;
prim->prec=0;
u=u->urm;
u->urm=0;
}
int numar(nodd *prim)
{nodd *p;
int k=0;
p=prim;
while(p)
{p=p->urm;
k++;
}
return k;
}
void main()
{creare(prim);
afis(prim);
int n=numar(prim);
for(int i=1;i<=n;i++)
{mutapu(prim);
afis(prim);
}
}
|