#include struct list { int pow,coef; struct list *next,*pre; }; typedef struct list node; typedef node *link; link last; link find(link h,int c, int p) { link ptr; ptr=h; do { if ((ptr->coef == c) && (ptr->pow == p)) return ptr; ptr=ptr->next; } while (ptr != NULL); return NULL; } void print_forward(link head) { link pt1; printf("the input polynomial ---> f(X)="); pt1=head; do { if (pt1->pow != 0) printf("%2dX%2d",pt1->coef,pt1->pow); else printf("%2d",pt1->coef); pt1=pt1->next; if (pt1 != NULL) printf("+"); } while (pt1 != NULL) ; printf("\n"); } void print_backward(link last) { link pt1; printf("the input polynomial ---> f(X)="); pt1=last; do { if (pt1->pow != 0) printf("%2dX%2d",pt1->coef,pt1->pow); else printf("%2d",pt1->coef); pt1=pt1->pre; if (pt1 != NULL) printf("+"); } while (pt1 != NULL) ; printf("\n"); } link create() { link pt1,pt2,head; int c,p; head=NULL; while (1) { printf("give me coefficient and power ?"); scanf("%d %d",&c,&p); if ((c == 0) && (p == 0)) break; pt2=(link)malloc(sizeof(node)); if (head == NULL) { pt1=head=pt2; pt1->pre=NULL; } else { pt1->next=pt2; pt2->pre=pt1; pt1=pt2; } pt2->coef=c; pt2->pow=p; } if (head != NULL) { pt2->next=NULL; last=pt2; } return head; } void conpoly(link h2,link l1) { link pt1,pt2; int c,p; l1->next=h2; h2->pre=l1; } void main() { link h1,l1,h2,l2; printf("give me the first polynomial -->"); h1=create(); l1=last; print_forward(h1); print_backward(l1); h2=create(); l2=last; print_forward(h2); print_backward(l2); conpoly(h2,l1); l1=l2; print_forward(h1); print_backward(l2); }