#define _crt_secure_no_warnings
#include #include #include typedef struct polyomial
*poly, polyomial; //poly為結點指標型別
void insert(poly p, poly h)
if (q2 && p->exp == q2->exp)
} else }}
poly createpoly(poly head, int m)
return head;
}void destroypoly(poly p)
}void printpoly(poly p)
while (q)
else
if (q->coef == -1)
} q = q->next;
flag++;
} printf("\n");
}int compare(poly a, poly b)
else if (!a && b)
return -1;//a多項式已空,但b多項式非空
else
return 1;//b多項式已空,但a多項式非空
}poly addpoly(poly pa, poly pb)
case 0:
case -1:
}if (qc->coef != 0)
else
free(qc);//當相加係數為0時,釋放該結點
} return headc;
}poly subtractpoly(poly pa, poly pb)
pd = addpoly(pa, h);
for (p = h->next; p; p = p->next) //恢復pb的係數
p->coef *= -1;
return pd;
}void menu()
int main()
if (flag == 2)
if (flag == 3)
if (flag == 4)
break;
if (flag<1 || flag>4)
printf("輸入錯誤,請重新輸入!\n");
continue;
} destroypoly(pa);
destroypoly(pb);
system("pause");
return 0;
}
一元稀疏多項式加減
一元稀疏多項式加減 include include include define ok 1 define error 0 typedef int status typedef struct pnodepnode,polynomial 建立乙個多項式鍊錶 status creatpolynnomial...
一元多項式的相加減
include include typedef struct node polynode polynode create int n r next null return l void add polynode pa,polynode pb else if p exp q exp 指數相等時,係數相...
一元稀疏多項式計算器(加減)
思路 1.首先是建立鍊錶,再儲存資料。2.進行多項式的運算。通過每一項的比較,判斷指數是否相等,相等就進行合併,不相等就不操作並找到下一項。這道題主要是考察了鍊錶的操作,估計很多人都會被繞暈了,不知道指標指向了 我已開始也敗在了指向問題上,在加法操作中,把pa,pb鍊錶記憶體的資料元素全都改變了,又...