#include struct list { int pow,coef; struct list *next; }; typedef struct list node; typedef node *link; link find(link h,int c, int p) { link ptr; ptr=h; while (ptr != NULL) { if ((ptr->coef == c) && (ptr->pow == p)) break; ptr=ptr->next; } return ptr; } 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() { int c,p; link head,pt1,pt2; head=NULL; while (1) { printf("give me poly ?"); scanf("%d %d",&c,&p); if ((c == 0) && (p == 0)) break; pt2=(link)malloc(sizeof(node)); pt2->next=NULL; if (head == NULL) pt1=head=pt2; else pt1=pt1->next=pt2; pt2->coef=c; pt2->pow=p; } return head; } link inspoly(link head) { link pt1,pt2; int c,p,c1,p1; while (1) { printf(" give me the node to insert after --> ");scanf("%d %d",&c,&p); if ((c == 0) && (p == 0)) break; printf(" give me the data (c,p) to insert --> ");scanf("%d %d",&c1,&p1); pt1=find(head,c,p); if (pt1 == NULL) printf("no such node to insert after!!\n"); else { /* insert head,middle,end */ pt2=(link)malloc(sizeof(node)); pt2->coef=c1; pt2->pow=p1; if (pt1 == head) { pt2->next=head; head=pt2; } /* insert head */ else { /* insert end , middle */ pt2->next=pt1->next; pt1->next=pt2; } /* else */ } /* else */ } return head; } void main() { link h1; printf("give me the first polynomial -->"); h1=create(); print_poly(h1); h1=inspoly(h1); print_poly(h1); }