




已阅读5页,还剩28页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
利用链表处理多项式,程序分块,1.编出制造多项式的函数creatlist(); llink creatlist()/制造多项式 llink head,p; int code,j,k,guard; printf(“请输入多项式项数n“); label: k=scanf(“%d“, ,printf(“按系数-指数的顺序初始化多项式n“); printf(“输入格式:系数和指数间有一逗号隔开n“); head=(llink)malloc(sizeof(node); if(!head) printf(“内存分配失败n“); exit(1); head-fin=-1; head-tak=-1; head-next=NULL; p=head;,for(j=0;jnext=(llink)malloc(sizeof(node); if(!p-next) printf(“内存分配失败n“); exit(1); guard=scanf(“%f,%f“, ,p-next-next=NULL; p=p-next; p-next=head;/创建循环链表 return head; 编出制造多项式函数后,下面编造其他功能函数 /计算多项式值的函数,要把头指针传进去 double result(llink head) llink p; float x; double sum=0; p=head-next; printf(“请输入未知数的值n“); scanf(“%f“,while(p!=head) sum+=(p-tak)*pow(x,p-fin); p=p-next; return sum; /多项式求导函数,把多项式的头指针传进去 qiudao (llink head) llink p,q,r;,p=head-next; r=(llink)malloc(sizeof(node);/设置头结点,为创建循环链表 if(!r) printf(“内存分配失败n“); exit(1); r-fin=-1; r-tak=-1; q=r; q-next=NULL;,while(p!=head) q-next=(llink)malloc(sizeof(node); if(!q-next) printf(“内存分配失败n“); exit(1); q-next-next=NULL; q-next-fin=p-fin-1; q-next-tak=(p-fin)*(p-tak); p=p-next; q=q-next; q-next=r;/将链表首尾连接起来,创建循环链表,printf(“求导后的多项式是:“); q=r-next; while(q!=r) printf(“%.2fX%.2f“,q-tak,q-fin); q=q-next; if(q-tak0 ,/多项式求积分函数,要传入多项式头指针传进去 jifen(llink head) llink p,q,r; p=head-next; r=(llink)malloc(sizeof(node); if(!r) printf(“内存分配失败n“); exit(1); r-next=NULL; r-fin=-1; r-tak=-1; q=r,while(p!=head) q-next=(llink)malloc(sizeof(node); if(!q-next) printf(“内存分配失败n“); exit(1); q-next-fin=p-fin+1;/根据积分运算原则,来为新多项式初始化 q-next-tak=p-tak/q-next-fin; p=p-next; q=q-next; q-next=r; q=r; q=q-next;,while(q!=r) printf(“%.2fX%.2f“,q-tak,q-fin); q=q-next; if(q-tak0 ,/计算两多项式和的函数的函数 llink add(llink plo,llink plp) llink head1,head2,result,before,check,another; head1=plo-next; head2=plp-next; result=(llink)malloc(sizeof(node);/创建头结点,为创建循环链表 if(!result) return NULL; result-fin=-1;/头结点初始化 result-tak=-1; before=result;/另一同类型指针来造出剩余结点,制造头结点的指针不能改变,以便返回该指针 before-next=NULL;,while(plo!=head1|plp!=head2)/分三种情况,依据指数的大小分类 before-next=(llink)malloc(sizeof(node); if(!before-next) printf(“内存分配失败n“); exit(1); before-next-next=NULL; if(head1-finhead2-fin) before-next-fin=head1-fin; before-next-tak=head1-tak; head1=head1-next; before=before-next; ,else if(head1-finfin) before-next-fin=head2-fin; before-next-tak=head2-tak; head2=head2-next; before=before-next; else before-next-fin=head1-fin; before-next-tak=head1-tak+head2-tak; head1=head1-next; head2=head2-next; before=before-next; ,before-next=result;/将链表首尾连接起来,创建循环链表 check=result-next; another=result-next; while(another-fin!=-1) if(another-fin=check-next-fin) another-tak+=check-next-tak; check-next=check-next-next; check=check-next; if(check-fin=-1) another=another-next; check=another; return result; ,/多项式相减 llink minus(llink plo,llink plp) llink head1,head2,result,before,check,another; head1=plo-next; head2=plp-next; result=(llink)malloc(sizeof(node);/创建头结点,为创建循环链表 if(!result) return NULL; result-fin=-1;/头结点初始化 result-tak=-1; before=result;/另一同类型指针来造出剩余结点,制造头结点的指针不能改变,以便返回该指针 before-next=NULL;,while(plo!=head1|plp!=head2)/分三种情况,依据指数的大小分类 before-next=(llink)malloc(sizeof(node); if(!before-next) printf(“内存分配失败n“); exit(1); before-next-next=NULL; if(head1-finhead2-fin) before-next-fin=head1-fin; before-next-tak=head1-tak; head1=head1-next; before=before-next; ,else if(head1-finfin) before-next-fin=head2-fin; before-next-tak=-head2-tak; head2=head2-next; before=before-next; else before-next-fin=head1-fin; before-next-tak=head1-tak-head2-tak; head1=head1-next; head2=head2-next; before=before-next; before-next=result;/将链表首尾连接起来,创建循环链表 check=result-next; another=result-next;,while(another-fin!=-1) if(another-fin=check-next-fin) another-tak+=check-next-tak; check-next=check-next-next; check=check-next; if(check-fin=-1) another=another-next; check=another; return result; ,/打印多项式函数 putout(llink head) llink ptr; ptr=head-next; while(ptr!=head) printf(“%.2fX%.2f“,ptr-tak,ptr-fin); ptr=ptr-next; if(ptr-tak0)/头结点初始化时,系数为-1,所以不必在加另一个约束条件 printf(“+“); printf(“n“); ,/多项式相乘函数 llink cheng(llink p1,llink p2) llink p,q,s,result,check,another; p=p1-next; q=p2-next; result=(llink)malloc(sizeof(node); if(!result) printf(“内存分配失败n“); exit(1); result-fin=-1; result-tak=-1; s=result;,while(p!=p1) while(q!=p2) s-next=(llink)malloc(sizeof(node); if(!s-next) printf(“内存分配失败n“); exit(1); s-next-tak=p-tak*q-tak; s-next-fin=p-fin+q-fin; q=q-next; s=s-next; p=p-next; q=p2-next; s-next=result; check=result-next; another=result-next;,while(another-fin!=-1)/此处校验相同指数项并合并他们 if(another-fin=check-next-fin) another-tak+=check-next-tak; check-next=check-next-next; check=check-next; if(check-fin=-1) another=another-next; check=another; return result; ,/释放内存函数 freelist(llink dsp) llink ptr,prl; prl=dsp; ptr=NULL; prl=prl-next; while(ptr!=dsp) ptr=prl; prl=prl-next; free(ptr); ,/功能实现函数 function(llink head1,llink head2) llink head3,head4;double sum1,sum2; int king; printf(“按如下列数字进行功能选择:n“); printf(“1.打出两个多项式t2.两多项式相加n“); printf(“3.输入未知数,计算两多项式的数值,并比较大小n“); printf(“4.对两多项式求导t5.对两多项式求积分n“); printf(“6.求两多项式的积t7.退出程序,释放内存n“); printf(“8.重新输入多项式,重新进行处理n“); printf(“9.计算多项式的差n“);,for(;) scanf(“%d“, , printf(“积分后的多项式:“); printf(“第一个多项式积分结果n“); jifen(head1); printf(“第二个多项式积分结果n“); jifen(head2); break; case 4: printf(“求导后多项式n“); printf(“第一个多项式求导结果n“); qiudao(head1); printf(“第二个多项式求导结果n“); qiudao(head2); break; ,case 3: printf(“请输入第一个多项式的未知数数值n“); sum1=result(head1); printf(“请输入第二个多项式的未知数数值n“); sum2=result(head2); printf(“第一个多项式和第二个多项式的值分别为:“); printf(“%.2ft%.2fn“,sum1,sum2); if(sum1sum2) printf(“f1f2n“); else if(sum1sum2) printf(“
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 心态培训课程员工培训
- 生产报表数据培训
- 新员工入职培训
- 播音选拔考试题库及答案
- 2025年应急救护知识竞赛试题及答案
- 中职公共课考试题及答案
- 中医康复师考试题目及答案大全
- 2025农业银行秋招笔试题及答案
- 2025四川广安市岳池县临溪镇人民政府招聘社区专职网格员2人考试参考题库及答案解析
- 2025招商银行宁波分行社会招聘(慈溪、余姚地区)考试参考题库及答案解析
- 台湾问题演讲稿
- 基本建设会计制度
- 冰激凌原料采购合同范例
- 清洁生产简述与实例分析课件
- 《机器视觉技术及其应用》课件-模块1项目1 机器视觉技术简介
- 《抗心律失常药》课件
- 帕金森病患者吞咽障碍康复中国专家共识 2025版解读
- GB/T 45166-2024无损检测红外热成像检测总则
- 混合动力汽车试卷B
- 制鞋工艺流程
- 2025年高考作文备考:写好主体段增强阐释性
评论
0/150
提交评论