#include struct list { int pow,coef; struct list *next; }; typedef struct list node; typedef node *link; void print_poly(link head) { link pt1; printf("the input polynomial ---> f(X)="); pt1=head; while (pt1 != NULL) { if (pt1->pow != 0) printf("%2dX%2d",pt1->coef,pt1->pow); else printf("%2d",pt1->coef); pt1=pt1->next; if (pt1 != NULL) printf("+"); } printf("\n"); } link create() { link head,pt1,pt2,pt3; int c,p,i; head=NULL; i=0; while (1) { printf("give me coefficient and power ?"); scanf("%d %d",&c,&p); if ((c == 0) && (p == 0)) break; if (i == 0) { i=1; head=pt2=(link)malloc(sizeof(node)); pt2->coef=c; pt2->pow=p; pt2->next=NULL; } else { /* 2th node after */ if (p > head->pow) { /* insert head */ pt2=(link)malloc(sizeof(node)); pt2->coef=c; pt2->pow=p; pt2->next=head; head=pt2; } else { /* insert middle, end */ pt3=head; while (pt3->pow > p) { pt1=pt3; pt3=pt3->next; } /* pt3->pow < = p */ if (pt3->pow == p) pt3->coef+=c; else { /* < */ pt2=(link)malloc(sizeof(node)); pt2->coef=c; pt2->pow=p; pt2->next=pt1->next; pt1->next=pt2; } } } } return head; } void main() { int c,p; link h1; printf("give me the polymonial -->"); h1=create(); print_poly(h1); }