資料結構樹上的**~~練習留著以後複習
//view codepolynomial.h
#include
using
namespace
std;
struct
pnode
pnode(
int& d,int& c,pnode *n=null)
};class
polynomial
polynomial(
int& d,int &c)
bool insert(); //
插入 pnode*gethead()
polynomial(polynomial &p1,polynomial &p2); //
多項式1 2相加放入3中
int getmax(); //
返回最大階數
friend polynomial operator +(polynomial &p1,polynomial &p2); //
多項式加法
friend polynomial operator *(polynomial &p1,polynomial &p2); //
多項式乘法
friend ostream& operator
<
輸出
else
if(p->ci==1
)
else
out; p=p->next;
}if (p->next==null)
else
if(p->ci==1
)
else
outp=p->next;
}return
out;
}
};bool
polynomial::insert()
return
true;};
intpolynomial::getmax()
p=p->next;
}return
i;};
polynomial::polynomial(polynomial &p1,polynomial &p2)
pnode *p=p1.gethead()->next;
while (p!=null)
p=p2.gethead()->next;
while (p!=null)
p=first=new
pnode;
for (int j=0;j<=i;j++)
p->next=null;
};polynomial
operator+(polynomial &p1,polynomial &p2)
pnode *p=p1.gethead()->next;
while (p!=null)
p=p2.gethead()->next;
while (p!=null)
polynomial p3;
p=p3.gethead();
for (int j=0;j<=i;j++)
p->next=null;
return
p3;};
polynomial
operator*(polynomial &p1,polynomial &p2)
pnode *p=p1.gethead()->next;
pnode *q=p2.gethead()->next;
while(p!=null)
p=p->next;
q=p2.gethead()->next;
}polynomial p3;
p=p3.gethead();
for (int j=0;j<=i;j++)
p->next=null;
return
p3;}
#include
#include
"polynomial.h
"using
namespace
std;
intmain()
cout
polynomial poly2;
poly2.insert();
p=poly2.gethead();
if(p->next==null)
cout
//polynomial poly3(poly1,poly2);
//多項式加法的一種
//cout
多項式加法
"<
polynomial poly3;
poly3=poly1+poly2;
cout
cout
<
多項式乘法
"<
polynomial poly4;
poly4=poly1*poly2;
cout
return0;
}
鍊錶實現多項式的加法和乘法
ifndef polynomialcompute poly h define polynomialcompute poly h struct polynode typedef struct polynode polynomial void attach int c,int e,polynomial ...
鍊錶應用 多項式加法 乘法
鍊錶學習 多項式應用 通過引入insertpoly函式來完成加法乘法操作 以及類似功能的creat 函式,使我的多項式按照指數下降的方式插入節點 而不需要在輸入時人為的控制 include using namespace std 多項式adt鍊錶實現的型別宣告 typedef struct node...
鍊錶實現的多項式加法與乘法
img public class node public node int a,int i public node public int geta public int geti public void seta int a public void seti int i 多項式類 單鏈表實現 pub...