网站大量收购独家精品文档,联系QQ:2885784924

数据结构实验代码重点.doc

  1. 1、本文档共13页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
《数据结构》实验代码 实验一:针对链式或顺序存储的线性表实现指定的操作 题1 问题描述:有两个指数递减的一元多项式,写一程序先求这两个多项式的和,再求它们的积。 题2 问题描述:编号为1,2,···,n的n个人围坐在一圆桌旁,每人持有一个正整数的密码。从第一个人开始报数,报到一个预先约定的正整数m时,停止报数,报m的人退席,下一个人又重新从1开始报数,依此重复,直至所有的人都退席。编一程序输出他们退席的编号序列。例如,设m=20,n=7,7个人的密码依次是3,1,7,2,4,8,4,则退席的人的编号依次为6,1,4,7,2,3,5。 n个人;要求建立此循环单链表;某人离席相当于删除一个结点,要正确设置程序中循环终止的条件和删除结点时指针的修改变化。 #includeiostream using namespace std; struct poNode { float coef; int expn; poNode *next; }; class Polynomail { public: Polynomail(int m=0); ~Polynomail(); int Print(); int PolynLength(); Polynomail AddPolyn(Polynomail P2,Polynomail P3); Polynomail MultiplyPolyn(Polynomail P2,Polynomail P4); private: int InsertpoNode(); poNode *first; }; int main() { int m; cout输入多项式P1项数endl; cinm; Polynomail P1(m); if(P1.PolynLength()!=m) { couterror!endl; return -1; } cout输入多项式P2项数endl; cinm; Polynomail P2(m); if(P2.PolynLength()!=m) { couterror!endl; return -1; } cout多项式P1:; P1.Print(); cout多项式P2:; P2.Print(); Polynomail P3; P3=P1.AddPolyn(P2,P3); coutP1+P2:; P3.Print(); Polynomail P4; P4=P1.MultiplyPolyn(P2,P4); coutP1*P2:; P4.Print(); return 0; } int Polynomail::InsertpoNode() { if(first==NULL) { first=new poNode; cout输入系数和指数:endl; cinfirst-coef; cinfirst-expn; first-next=NULL; } else { poNode *p=new poNode; poNode *q=first; cout输入系数和指数:endl; cinp-coef; cinp-expn; poNode *r; while(q-next!=NULLq-expnp-expn) { r=q; q=q-next; } if(q==firstq-next!=NULL) { if(q-expn==p-expn) { return -1; } p-next=q; first=p; } else if(q==firstq-next==NULL) { if(p-expnq-expn) { p-next=q; first=p; } else if(p-expnq-expn) { q-next=p; p-next=NULL; } else { return -1; } } else if(q-next==NULLq!=firstp-expnq-expn) { q-next=p; p-next=NULL; } else { if(q-expn==p-expn) { return -1; } r-next=p; p-next=q; } } return 0; } Polynomail::Polynomail(int m) { first=NULL; int i; for(i=0;im;i++) { int r=InsertpoNode(); if(r==-1)

文档评论(0)

shuwkb + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档