一元多项式相加C语言代码.docx

上传人:牧羊曲112 文档编号:3191286 上传时间:2023-03-11 格式:DOCX 页数:4 大小:36.88KB
返回 下载 相关 举报
一元多项式相加C语言代码.docx_第1页
第1页 / 共4页
一元多项式相加C语言代码.docx_第2页
第2页 / 共4页
一元多项式相加C语言代码.docx_第3页
第3页 / 共4页
一元多项式相加C语言代码.docx_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《一元多项式相加C语言代码.docx》由会员分享,可在线阅读,更多相关《一元多项式相加C语言代码.docx(4页珍藏版)》请在三一办公上搜索。

1、一元多项式相加C语言代码数据结构作业 一元多项式相加C语言代码 #include #include typedef struct node int exp,coef; struct node *link; PolyNode,*Polylinklist; Polylinklist Creat(int n) Polylinklist p,r=NULL,list=NULL; int coef,exp,i; for(i=1;icoef=coef; p-exp=exp; p-link=NULL; if(list=NULL) list=p; else r-link=p; r=p; return(list)

2、; Polylinklist ATTACH(int coef,int exp,Polylinklist r) Polylinklist w; w=(Polylinklist)malloc(sizeof(PolyNode); w-exp=exp; w-coef=coef; r-link=w; return w; Polylinklist PADD(Polylinklist a,Polylinklist b) Polylinklist c; Polylinklist r,p=a,q=b; int x; c=(Polylinklist)malloc(sizeof(PolyNode); r=c; wh

3、ile(p!=NULL&q!=NULL) if(p-exp=q-exp) x=p-coef+q-coef; if(x!=0) r=ATTACH(x,q-exp,r); p=p-link; q=q-link; else if(p-expexp) r=ATTACH(q-coef,q-exp,r); q=q-link; else r=ATTACH(p-coef,p-exp,r); p=p-link; while(p!=NULL) r=ATTACH(p-coef,p-exp,r); p=p-link; while(q!=NULL) r=ATTACH(q-coef,q-exp,r); q=q-link;

4、 r-link=NULL; p=c; c=c-link; free(p); return c; void Result(Polylinklist w) Polylinklist m; m=w; while(w=NULL) printf(0); break; while(w!=NULL) if(w-exp=0) printf(%d,w-coef); else printf(%d*x%d,w-coef,w-exp); w=w-link; while(w!=NULL) if(w-coef0) if(w-exp=0) printf(+%d,w-coef); else printf(+%d*x%d,w-

5、coef,w-exp); else if(w-exp!=0) printf(%d*x%d,w-coef,w-exp); else printf(%d,w-coef); w=w-link; void main Polylinklist c=NULL; PolyNode *Lengtha; PolyNode *Lengthb; int a1,b1; printf(Please input as Length:); scanf(%d,&a1); Lengtha=Creat(a1); printf( a=); Result(Lengtha); printf(n); printf(Please input bs Length:); scanf(%d,&b1); Lengthb=Creat(b1); printf( b=); Result(Lengthb); printf(n); c=PADD(Lengtha,Lengthb); printf(n); printf( c=); Result(c); printf(n);

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号