C 鍊錶實現多項式加法

2021-08-25 06:06:40 字數 619 閱讀 8900

#include #include typedef struct polynode

polynode, *polylist;

// 初始化多項式

bool initpoly(polylist *poly) // 二級指標

// 外插法建立一元多項式單鏈表,n代表多項式非零係數的個數

void polycreate(polylist head, int n)

rear->next = null; // 將表尾的最後乙個結點置為空 }

// 多項式相加

void polyadd(polylist polya, polylist polyb)

else if (p->exp == q->exp) // 係數相等,對應係數相加

else

}else

}if (p != null)

pre->next = p; // 將p剩餘結點加入到和多項式

else

pre->next = q;

}void printpoly(polylist poly)

printf("\n");

}int main()

鍊錶的多項式加法鍊錶的多項式加法

老師給的模板看的我不要不要的,真心難看,看了很久才把過載加法搞定了。include using namespace std include 定義結點類 用於表示多項式的一項 class node node int nexp,int ncoef private int exp 指數 int coef ...

多項式加法運算鍊錶實現

struct polynode typedef struct polynode polynomial polynomial p1,p2 polynomial polyadd polynomial p1,polynomial p2 多項式加法鍊錶實現 當while退出時,p1 p2有乙個為空。將未處理...

C語言鍊錶實現多項式加法乘法

資料結構 浙大版 多項式小記 include include typedef struct polynode polynomial struct polynode int compare int p1,int p2 void attach int c,int e,polynomial prear p...