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