#include #include #include struct cirlink { int x; struct cirlink *next; } *s1, *s2; void printp(struct cirlink *pp) { // circle link list struct cirlink *p; p=pp; printf("the input value is --> "); printf("%d ",p->x); p=p->next; while (p != pp) { printf("%d ",p->x); p=p->next; } printf("\n"); } struct cirlink * create() { int x,fg,ff; struct cirlink *pp,*p,*ppre,*pnext; ff=fg=0; while (1) { // the polynomial p1 printf("give me the data --> "); scanf("%d",&x); if (x == 0) break; if (ff == 0) { // 1st item ff=1; pp=p=(struct cirlink *)malloc(sizeof(struct cirlink)); p->x=x; p->next=p; continue; } // if else { ppre=pp; pnext=ppre->next; if (x >= ppre->x) { // insert into head if (x > ppre->x) { // eliminate the equal number p=(struct cirlink *)malloc(sizeof(struct cirlink)); p->x=x; p->next=pp; while (pnext != pp) { ppre=pnext; pnext=pnext->next;} ppre->next=p; pp=p; } } else { // x < start->x fg=0; if (pnext == pp) { // insert directly into the end p=(struct cirlink *)malloc(sizeof(struct cirlink)); p->x=x; p->next=pp; pp->next=p; continue; } else { while (pnext->x > x) { ppre=pnext; pnext=pnext->next; if (pnext == pp) { // insert into the end p=(struct cirlink *)malloc(sizeof(struct cirlink)); p->x=x; fg=1; ppre->next=p; p->next=pp; break; }// if } // while if (fg == 0) { // insert into the middle p=(struct cirlink *)malloc(sizeof(struct cirlink)); p->x=x; p->next=ppre->next; ppre->next=p; } } // else x < start-> x } // else not the 1st item } // else ff = 1 } // while return pp; } void main() { struct cirlink *p, *pnext; p=s1=create(); printp(s1); s2=create(); printp(s2); pnext=s1->next; while (pnext != s1) { p=pnext; pnext=pnext->next; } p->next=s2; p=s2; pnext=p->next; while (pnext != s2) { p=pnext; pnext=pnext->next; } p->next=s1; printp(s1); }