欢迎来到第壹文秘! | 帮助中心 分享价值,成长自我!
第壹文秘
全部分类
  • 幼儿/小学教育>
  • 中学教育>
  • 高等教育>
  • 研究生考试>
  • 外语学习>
  • 资格/认证考试>
  • 论文>
  • IT计算机>
  • 法律/法学>
  • 建筑/环境>
  • 通信/电子>
  • 医学/心理学>
  • ImageVerifierCode 换一换
    首页 第壹文秘 > 资源分类 > DOCX文档下载
    分享到微信 分享到微博 分享到QQ空间

    数据结构第三章到第九章练习题答案.docx

    • 资源ID:848133       资源大小:341.32KB        全文页数:30页
    • 资源格式: DOCX        下载积分:5金币
    快捷下载 游客一键下载
    账号登录下载
    三方登录下载: 微信开放平台登录 QQ登录
    下载资源需要5金币
    邮箱/手机:
    温馨提示:
    快捷下载时,如果您不填写信息,系统将为您自动创建临时账号,适用于临时下载。
    如果您填写信息,用户名和密码都是您填写的【邮箱或者手机号】(系统自动生成),方便查询和重复下载。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

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

    数据结构第三章到第九章练习题答案.docx

    第三章栈和队列借助栈实现单链表上的逆置运算。/Stdafx.h#include<iostream>#include<tchar.h>ttincludezztime.h"usingnamespacestd;结点类structLinkNodeintdata;1.inkNode*link;1.inkNode(constint&item,LinkNode*ptr=NULL)data=item;link=ptr;1.inkNode(LinkNode*ptr=NULL)link=ptr;;#Pragmaonce带附加头结点的单链表classList(public:1.ist(void);构造函数1.ist(constint&x);构造函数List(void);析构函数voidinput(intn);输入voidOUtPUt(VOid);输出voidmakcEmpty(void);清空voidinverse(void);逆转函数protected:1.inkNode*first;链表头指针;#Pragmaonceinclude.list.h"classstack(public:stack(void);“stack(VOid);protected:1.inkNode*top;friendclassList;public:voidPush(constint&x);boolPop();boolIsEmpty(void)return(top=NULL)?true:false;);Itinclude"StdAfx.h"include”.list.h"fusing<mscorlib.dll>1.ist:List(constint&x)(first=newLinkNode(x);)1.ist:List(void)(first=newLinkNode;)1.ist:List(void)(makeEmpty();)voidList:input(intn)(1.inkNode*newNode;first=newLinkNode;for(inti=0;i<n;i+)(intx=rand()%100;newNode=newLinkNode(x);newNode->1ink=first->link;first->link=newNode;)voidList:output(void)(1.inkNode*current=first->link;while(current!=NULL)(cout<<current->data<<zz;current=current->link;)cout<<endl;)voidList:makeEmpty(void)1.inkNode*p;whiIe(first->link!=NULL)p=first->link;first->link=p->link;deletep;)逆转函数voidList:inverse(void)(stacks;1.inkNode*p=first->link,*q;while(p!=NULL)(s.Push(p->data);p=p->link;)p=first->link;while(!s.IsEmptyO)(q=s.top;p->data=q->data;p=p->link;s.PopO;)include"StdAfx.hinclude”.stack.hfusing<mscorlib.dll>stack:stack(void):top(NULL)()stack:飞tack(void)()入栈voidstack:Push(constint&x)(top=newLinkNode(x,top);)出栈boolstack:Pop()(if(IsEmptyO-true)returnfalse;1.inkNode*p=top;top=top->link;deletep;returntrue;)include"stdafx.h"include.list.h"#usingll>usingnamespaceSystem;int_tmain()(srand(time(NULL);1.ist1;调用输入函数1.input(10);调用输出函数1.output();COUt<<调用逆转函数"<<endl;1.inverse();调用输出函数1.output();return0;QB数据结构作业3新建文件夹逆转Debug实套exeHglX7662241调用逆转函数217205Pressanykey367907221?9364122676tocontinue编写一个算法,将一个非负的十进制整数N转换为另一个基为B的B进制数。/stdafx.h#include<iostream>#include<tchar.h>usingnamespacestd;structLinkNodeintdata;1.inkNode*link;1.inkNode(constint&item,LinkNode*ptr=NULL)(data=item;link=ptr;1.inkNode(LinkNode*ptr=NULL)link=ptr;);#Pragmaonceclassstackpublic:stack(void);stack(void);voidPush(constint&x);boolPop(int&x);boolIsEmpty(void)return(top=NULL)?true:false;protected:1.inkNode*top;);Winclude"StdAfx.hincludestack.hfusing<mscorlib.dll>stack:stack(void):top(NULL)()stack:StaCk(VOid)()voidstack:Push(constint&x)(top=newLinkNode(x,top);)boolstack:Pop(int&x)(if(IsEmpty()=true)returnfalse;1.inkNode*p=top;top=top->link;x=p->data;deletep;returntrue;)#include"stdafx.hinclude”.stack.hfusing<mscorlib.dll>usingnamespaceSystem;int_tmain()(intn,m,temp,yu;COUt<<输入十进制数:;cin>>n;COUt<<输入基数:”;cin>>m;stack1;while(n!=O&&m!=0)temp=n%m;n=nm;1.Push(temp);)while(!1.IsEmptyO)1.Pop(yu);cout<<yu;cout<<endl;return0;)试编写一个算法,求解最大公因数问题:在求两个正整数m和n的最大公因数常常使用辗转相除法,反复计算直到余数为零为止。其递归定义为:/stdafx.h#include<iostream>include<tchar.h>#include<math.h>usingnamespacestd;intf(intnl,intn2);includezzstdafx.h"fusing<mscorlib.dll>usingnamespaceSystem;int_tmain()intnl,n2;COUt<<"Enterthefirstpositivenumber:"z<<end1;cin>>nl;cout<<zzEnterthesecondpositivenumber:"z<<endl;cin>>n2;if(nl>O&&n2>0)(cout<<nl<<"和<<n2<<的最大公约数是:<<f(nl,n2)<<endl;)elseCoUt<<非法数据<<endl;returnO;)intf(intnl,intn2)(intt;while(n2!=0)(t=nl%112inl=n2;n2=t;)returnnl;)3.23假设以数组Qm存放循环队列中的元素,同时设置一个标志tag,以tag=O和tag=l来区别在对头指针(fr。IIt)和对尾指针(rear)相等时,队列状态为“空”还是“满、试编写与此结构相应的插入(EnQueue)和删除(DeQlIelIe)算法。#include<iostream>Itinclude<tchar.h>ttinclude<time.h>usingnamespacestd;#pragmaonceclassSeqQueuepublic:SeqQueue(intsize=10);'SeqQucue(void);protected:intrear,front,tag;int*element;intmaxSize;public:boolEnQueue(constint&x);boolDeQueue(void);boolIsEmpty(void)return(front=rear&&tag=0)?true:false;boolIsFulKvoid)return(front=rear&&tag=l)?true:false;friendOStreaoperator<<(ostream&os,SeqQueueftQ);;include"StdAfx.h#include”.SeqQeue.httusing<mscorlib.dll>SeqQueue:SeqQueue(intsize):rear(O),front(O),tag(O),maxSize(size)(element=newintmaxSize;SeqQucue:SeqQucue(void)deleteelement;)boolSeqQueue:EnQueue(constint&x)if(IsFullO=true)returnfalse;elementrear=x;rear=(rear+l)%maxSize;tag=l;returntrue;)boolSeqQueue:DeQueue(void)if(IsEmpty()=true)returnfalse;front=(front+1)%maxSize;tag=0;returntrue;)Ostreamftoperator<<(ostream&os,SeqQueuefeQ)(in

    注意事项

    本文(数据结构第三章到第九章练习题答案.docx)为本站会员(p**)主动上传,第壹文秘仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知第壹文秘(点击联系客服),我们立即给予删除!

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




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

    copyright@ 2008-2023 1wenmi网站版权所有

    经营许可证编号:宁ICP备2022001189号-1

    本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。第壹文秘仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知第壹文秘网,我们立即给予删除!

    收起
    展开