- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
实习报告
一.实习题:
请写出计算两个以单链接表表示的多项式相乘的程序。
设计:
因为进行插入删除时,有头结点的单链表的实现会更方便,所以采用带头结点的单链表,
一个单链表代表一个多项式, 每个结点代表多项式的一个因子, 每个结点都有两个数据和一个指针,数据分别代表每个因子的系数和指数。
(1)存储结构:
结点类:
class Listnode
{
friend class List;
friend ostream operator (ostream output,const Listnode node);
private:
Listnode* next;//point to the next node
int coefficient;
int exponent;
public:
Listnode(const int e1,const int e2,Listnode*p=NULL)
:coefficient(e1),exponent(e2),next(p){}//constructor
with
three
parameters
Listnode()
:next(NULL){}//constructor without parameters
Listnode* Get(){return next;}//get the next
~Listnode(){}// 析构函数
};
单链表类:
class List
{
friend ostream operator (ostream output,List list);
friend istream operator (istream input,List list);
private:
Listnode* head;//point to the head of the list
Listnode* current;//point to the current node
public:
List(){head = new Listnode();current = head;}//constructor
~List(){Makeempty();delete head;}// 析构函数
int Isempty(){return head-next == NULL;}//if the list is empty return 1,else rerurn 0
void First(){current=head-next;}//make current point to the first node void operator ++()
{
if (current!=NULL)
current=current-next;
}//make current point to the next node
void operator ++(int){operator++();}
int Isfull(){}//the list is generally unable to be full
void Makeempty();//clear the list
int Find(const int x,const int y);//if (x,y) is in the list,return 1 void Insert(const int x,const int y);//insert a node to the list whose
element is (x,y),then current point to it
void Delete(const int x,const int y);//delete the node whose element is
(x,y)
const List operator = (const List list);//copy the right list to the left
one
List operator +(List list);//get the sum of two lists
List operator *(List list);//get the multiply of the two lists
};
(2)算法思想:
设多项式 A, B, A 有 m项, B 有 n 项,用 A 中的每一项乘以 B 得到 m个 n 项式,然后这 m
个 n 项式相加,即得到 A 与 B 相乘的结果。
(3)程序调用关系:
此次实习的主程序比较简单,只涉及类的成员函数之间的调用。
(4) 算法实现框架:
定义两个单链
表存储两个多
项式
依次让用户输
入两个多项式
的数据
将数据存入到
两个单链表中
按照算法进
行两个多项
式相加
将
您可能关注的文档
- 华师在线中外学前教育史上半答案.docx
- 华师春高升专经济法在线作业答案.docx
- 华师网络教育学院教育统计与评价复习资料.docx
- 华庆变压器厂.管理规章制度.docx
- 华强立交材料试验、质检仪器设备表.docx
- 华政老师自己出的中法史模拟题.docx
- 华泰汽车4s店申请计划书.docx
- 华电自动化专题――大型火电厂分散控制系统设计新进展..docx
- 华润啤酒(阜阳二期)施工组织设计.docx
- 华电软件测试实验报告.docx
- AI+产业重启介绍.pptx
- 虚拟电厂市场发展近况与盈利模式实践.pdf
- 2025年带电作业技术会议:低压不停电作业全绝缘手工工具研发与应用.pptx
- 2025 年人工智能市场报告:关键数据与创新 Artificial Intelligence Market Report 2025 Key Data & Innovations.pdf
- 2025双11好东西宝典.docx
- 2025年带电作业技术会议:低压不停电作业典型场景技术研究与装备应用.pptx
- AI智能体威胁与缓解措施.pdf
- 2025 年欧洲创新记分牌 European Innovation Scoreboard 2025.pdf
- 2025户外生活方式白皮书.pdf
- 人教版七年级下册英语(2025 春版)单元知识梳理.pdf
原创力文档


文档评论(0)