• 2020-05-30 20:53:48
• OfStack

In this paper, the example of C language single linked list to realize the addition of polynomial specific code, for your reference, the specific content is as follows

``````
#include<stdio.h>
#include<stdlib.h>
#pragma warning(disable:4996)// Compatible with scanf
typedef struct node {
int coef;
int expon;
}Polynode,*Polynomial;
}

int N;
scanf("%d ", &N);
while (N--) {
Polynomial p = (Polynomial)malloc(sizeof(Polynode));
scanf("%d %d", &p->coef, &p->expon);
}
Polynomial F;
free(H);
return F;
}
void PrintPoly(Polynomial F) {
while(F != NULL) {
printf("%d %d ", F->coef, F->expon);
}
printf("\n");
}
Polynomial Add(Polynomial p1, Polynomial p2) {
Polynomial t1=p1,t2=p2;
Polynomial p=(Polynomial)malloc(sizeof(Polynode));
Polynomial q = p;
while (t1&&t2) {
if (t1->expon == t2->expon) {
if (t1->coef + t2->coef) {
t1->coef = t1->coef + t2->coef;
t1->expon = t1->expon;
}
}
else {
if (t1->expon > t2->expon){
}
else {
if (t1->expon < t2->expon) {
}
}
}
}
if (t1) {
}
if (t2) {
}
free(p);
return F;
}
int main(void) {
Polynomial p1, p2, pp, ps;
PrintPoly(p1);
PrintPoly(p2);