欢迎来到三一办公! | 帮助中心 三一办公31ppt.com(应用文档模板下载平台)
三一办公
全部分类
  • 办公文档>
  • PPT模板>
  • 建筑/施工/环境>
  • 毕业设计>
  • 工程图纸>
  • 教育教学>
  • 素材源码>
  • 生活休闲>
  • 临时分类>
  • ImageVerifierCode 换一换
    首页 三一办公 > 资源分类 > PPT文档下载  

    数据结构与程序设计(王丽苹)10-多项式的例子.ppt

    • 资源ID:4980177       资源大小:307.11KB        全文页数:33页
    • 资源格式: PPT        下载积分:15金币
    快捷下载 游客一键下载
    会员登录下载
    三方登录下载: 微信开放平台登录 QQ登录  
    下载资源需要15金币
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    数据结构与程序设计(王丽苹)10-多项式的例子.ppt

    5/27/2023,数据结构与程序设计,1,数据结构与程序设计(10),王丽苹,5/27/2023,数据结构与程序设计,2,应用:多项式求解,后序波兰式的求解abc-d*(1)如果a,b,c为整数如何求解。(2)如果a,b,c为多项式如何求解。,AH=7x14+2x8+-10 x6+1 BH=4x18+8x14-3x10+10 x6-x4,5/27/2023,数据结构与程序设计,3,多项式及其相加在多项式的链表表示中每个结点增加了一个数据成员link,作为链接指针。优点是:多项式的项数可以动态地增长,不存在存储溢出问题。插入、删除方便,不移动元素。,链接队列和栈的综合应用,5/27/2023,数据结构与程序设计,4,多项式链表的相加,AH=7x14+2x8+-10 x6+1 BH=4x18+8x14-3x10+10 x6-x4,7 14,2 8,-10 6,1 10,4 18,8 14,-3 10,10 6,-1 4,4 18,15 14,-3 10,2 8,-1 4,1 10,AH.first,BH.first,CH.first,5/27/2023,数据结构与程序设计,5,链接队列和栈的综合应用,目录Polynomial下例程,5/27/2023,数据结构与程序设计,6,链接队列和栈的综合应用,top_node,Polynomialnext,Polynomialnext,class Stackprotected:Node*top_node;,struct Node Polynomial entry;Node*next;,5/27/2023,数据结构与程序设计,7,链接队列和栈的综合应用,Polynomial,Term next,Term next,class Queue protected:SmallNode*front,*rear;,class SmallNode public:Term entry;SmallNode*next;,Term next,front,rear,5/27/2023,数据结构与程序设计,8,链接队列和栈的综合应用,class Term public:int degree;double coefficient;,degreecoefficient,Eg:3x2degree=2coefficient=3,5/27/2023,数据结构与程序设计,9,链接队列和栈的综合应用-Term,class Term public:Term(int exponent=0,double scalar=0);int degree;double coefficient;,5/27/2023,数据结构与程序设计,10,链接队列和栈的综合应用-Term,#includeTerm.hTerm:Term(int exponent,double scalar)/*Post:The Term is initialized with the given coefficient and exponent,or with default parameter values of 0.*/degree=exponent;coefficient=scalar;,5/27/2023,数据结构与程序设计,11,链接队列和栈的综合应用-Polynomial,typedef Term Queue_entry;typedef Term SmallNode_entry;class SmallNode/data memberspublic:SmallNode_entry entry;SmallNode*next;/constructorsSmallNode();SmallNode(SmallNode_entry item,SmallNode*add_on=0);,5/27/2023,数据结构与程序设计,12,链接队列和栈的综合应用-Polynomial,class Queue public:/standard Queue methodsQueue();bool empty()const;Error_code append(const Queue_entry/Queue表示一个多项式,5/27/2023,数据结构与程序设计,13,链接队列和栈的综合应用-Polynomial,class Extended_queue:public Queue public:int size()const;void clear();Error_code serve_and_retrieve(Queue_entry,5/27/2023,数据结构与程序设计,14,链接队列和栈的综合应用-Polynomial,class Polynomial:private Extended_queue/Use private inheritance.public:Polynomial();Polynomial:Polynomial(const Polynomial/用Polynomial来封装Queue,Polynomial表示一个多项式,5/27/2023,数据结构与程序设计,15,链接队列和栈的综合应用-Polynomial,Polynomial:Polynomial()front=NULL;rear=NULL;,5/27/2023,数据结构与程序设计,16,链接队列和栈的综合应用-Polynomial,Polynomial:Polynomial(const Polynomial,5/27/2023,数据结构与程序设计,17,Linked Queues-Queue,original_frontnew_front new_copynew_front new_copy,5/27/2023,数据结构与程序设计,18,链接队列和栈的综合应用-Polynomial,void Polynomial:operator=(const Polynomial,5/27/2023,数据结构与程序设计,19,链接队列和栈的综合应用Polynomialp147,void Polynomial:print()const/*Post:The Polynomial is printed to cout.*/SmallNode*print_node=front;bool first_term=true;while(print_node!=NULL)Term,5/27/2023,数据结构与程序设计,20,Linked Queues-Queue,print_node,5/27/2023,数据结构与程序设计,21,链接队列和栈的综合应用Polynomialp148,void Polynomial:read()clear();double coefficient;int last_exponent,exponent;bool first_term=true;cout coefficient;if(coefficient!=0.0)cout exponent;if(!first_term,5/27/2023,数据结构与程序设计,22,链接队列和栈的综合应用-Polynomial,int Polynomial:degree()const/*Post:If the Polynomial is identically 0,a result of-1 is returned.Otherwise the degree of the Polynomial is returned.*/if(empty()return-1;Term lead;retrieve(lead);return lead.degree;,5/27/2023,数据结构与程序设计,23,链接队列和栈的综合应用Polynomialp149,void Polynomial:equals_sum(Polynomial p,Polynomial q)clear();while(!p.empty()|!q.empty()Term p_term,q_term;if(p.degree()q.degree()p.serve_and_retrieve(p_term);append(p_term);else if(q.degree()p.degree()q.serve_and_retrieve(q_term);append(q_term);else p.serve_and_retrieve(p_term);q.serve_and_retrieve(q_term);if(p_term.coefficient+q_term.coefficient!=0)Term answer_term(p_term.degree,p_term.coefficient+q_term.coefficient);append(answer_term);,5/27/2023,数据结构与程序设计,24,链接队列和栈的综合应用Link Stack,typedef Polynomial Node_entry;struct Node/data members Node_entry entry;Node*next;/constructors Node();Node(const Node_entry item,Node*add_on=0);,5/27/2023,数据结构与程序设计,25,链接队列和栈的综合应用Link Stack,class Stackpublic:/Standard Stack methods Stack();bool empty()const;Error_code push(const Node_entry,5/27/2023,数据结构与程序设计,26,链接队列和栈的综合应用Main,void main()/*Post:The program has executed simple polynomial arithmetic commands entered by the user.Uses:The classes Stack and Polynomial and the functions introduction,instructions,do_command,and get_command.*/Stack stored_polynomials;void introduction();void instructions();bool do_command(char command,Stack,5/27/2023,数据结构与程序设计,27,链接队列和栈的综合应用Main,void introduction()coutThis is a polynomials program.endl;void instructions()cout Please enter a valid command:endl?Read a Polynomial endl=Return Top Polynomial endl+Sum two Polynomial endl q Quit.endl;,5/27/2023,数据结构与程序设计,28,链接队列和栈的综合应用Mainp143,bool do_command(char command,Stack switch(command),5/27/2023,数据结构与程序设计,29,链接队列和栈的综合应用Main,case?:p.read();if(stored_polynomials.push(p)=overflow)cout Warning:Stack full,lost polynomial endl;break;case=:if(stored_polynomials.empty()cout Stack empty endl;else stored_polynomials.top(p);p.print();break;,5/27/2023,数据结构与程序设计,30,链接队列和栈的综合应用Main,case+:if(stored_polynomials.empty()cout Stack empty endl;else stored_polynomials.top(p);stored_polynomials.pop();if(stored_polynomials.empty()cout Stack has just one polynomial endl;stored_polynomials.push(p);else stored_polynomials.top(q);stored_polynomials.pop();r.equals_sum(q,p);if(stored_polynomials.push(r)=overflow)cout Warning:Stack full,lost polynomial endl;break;,5/27/2023,数据结构与程序设计,31,链接队列和栈的综合应用Main,case q:cout Calculation finished.endl;return false;return true;,5/27/2023,数据结构与程序设计,32,链接队列和栈的综合应用Main,char get_command()char command;bool waiting=true;cout:;while(waiting)cin command;command=tolower(command);if(command=?|command=|command=+|command=q)waiting=false;else cout Please enter a valid command:endl?Read a Polynomial endl=Return Top Polynomial endl+Sum two Polynomial endl q Quit.endl;return command;,5/27/2023,数据结构与程序设计,33,上机作业,实现polynomial补充功能P151 P2P151 P3,

    注意事项

    本文(数据结构与程序设计(王丽苹)10-多项式的例子.ppt)为本站会员(小飞机)主动上传,三一办公仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一办公(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    备案号:宁ICP备20000045号-2

    经营许可证:宁B2-20210002

    宁公网安备 64010402000987号

    三一办公
    收起
    展开