I like to do other people's homework
if it's interesting and not too hard.
I do too. This is one of my favorites:
--------
#include <stdio.h>
#include <stdlib.h>
typedef struct n{struct n*p1,*p2;int v;}n;n*r_t(n*p,n*i){n*i2,*t1,*t2;int v
;if(!i)return 0;while(p->p2)p=p->p2;i2=i;do{t1=malloc(sizeof*t1);t2=malloc(
sizeof*t2);if(!t1||!t2)return 0;t1->v=t2->v=i2->v;t2->p1=t2->p2=0;t1->p1=i2
;t1->p2=t2;if(t1->p1->p2)t1->p1->p2->p1=t1;if(t1->p1->p1)t1->p1->p1->p1->p2
=t1;i2=t1->p1->p2;}while(i2);i=t1;while(i->p1->p1){i2=i;v=i2->v;while(p->v!=
v&&p->p1->v!=v){i2=i2->p1->p1;if(!i2){fputs("(1)\n",stderr);return 0;}v=i2
->v;}if(v==p->v){if(p->p1){p=p->p1;free(p->p2);p->p2=0;}else{fputs("(2)\n",
stderr);return 0;}if(i2->p1->p1)i2->p1->p1->p1->p2=i2->p1->p2;if(i2->p1->p2
)i2->p1->p2->p1->p1=i2->p1->p1;else i=i2;t1=i2->p2;t2=i2->p1->p1;free(i2->
p1);free(i2);t2->p2->p2=t1;}else{t2=p->p1;if(t2->p1)t2->p1->p2=t2->p2;t2->p2
->p1=t1->p1;free(t2);i2=i2->p1->p1;if(i2->p1->p1)i2->p1->p1->p1->p2=i2->p1->
p2;i2->p1->p2->p1->p1=i2->p1->p1;t1=i2->p2;t2=i2->p1->p2;free(i2->p1);free(
i2);t2->p2->p1=t1;}}if(p->p1||p->p2)fputs("(3)\n",stderr);free(p);if(i->p1->
p1||i->p1->p2)fputs("(4)\n",stderr);t1=i->p2;free(i->p1);free(i);return t1;}
--------
I'm one of the dangerous people on USENET
that your mother warned you about.
I'm an entirely different kind of dangerous people on USENET, the kind
your mother never thought you'd need to be warned about.
dave
(I remember that there was a bug in my first version of that one. I have
no idea whether it's been fixed in the version I have laying around.)