一元稀疏多項式的計算(資料結構C 版)

2021-10-01 15:25:14 字數 1750 閱讀 6279

**

[基本要求]

(1)能夠按照指數降序排列建立並輸出多項式(公升序只需稍微改動一下**);

(2)能夠完成兩個多項式的相加、相減,並將結果輸出;

(3)以鏈式儲存結構實現多項式。

[**實現]

//測試資料:2 1 4 3 5 2      78 1 3 2 4 3 6 4

#include

using

namespace std;

typedef

struct pnode

pnode,

*polynomial;

void

createpolyn

(polynomial &p,

int n)

s->next = q;

//s插入到pre與q之間

pre-

>next = s;}}

void

print

(polynomial &p)

if(q-

>zhishu ==1)

cout << q-

>xishu <<

"x";

else

cout << q-

>xishu <<

"x^"

<< q-

>zhishu;

}void

add(polynomial &pa, polynomial &pb)

else

}else

if(p1-

>zhishu > p2-

>zhishu)

else

} p3-

>next = p1 ? p1 : p2;

delete pb;

pnode *p4 = pa-

>next;

while

(p4&&p4-

>next)

if(p4-

>zhishu ==1)

cout << p4-

>xishu<<

"x";

else

cout<< p4-

>xishu <<

"x^"

<< p4-

>zhishu;

}void

cut(polynomial &pa, polynomial &pb)

else

}else

if(p1-

>zhishu > p2-

>zhishu)

else

} p3-

>next = p1 ? p1 : p2;

delete pb;

pnode *p4 = pa-

>next;

while

(p4&&p4-

>next)

if(p4-

>zhishu ==1)

cout << p4-

>xishu<<

"x";

else

cout << p4-

>xishu <<

"x^"

<< p4-

>zhishu;

}int

main()

[實現]

一元稀疏多項式的計算

能夠按照指數降序排列建立並輸出多項式 能夠完成兩個多項式的相加 相減,並將結果輸出 以鏈式儲存結構實現多項式。include include includeusing namespace std typedef struct pnode pnode,polynomial void createpol...

資料結構 一元多項式

void initlist polynode l 初始化多項式單鏈表 int getlength polynode l 求多項式單鏈表的長度 polynode getelem polynode l,int i 返回多項式單鏈表中第i個結點的指標 polynode locate polynode l,...

一元稀疏多項式加減

一元稀疏多項式加減 include include include define ok 1 define error 0 typedef int status typedef struct pnodepnode,polynomial 建立乙個多項式鍊錶 status creatpolynnomial...