- 1、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
(精品课件)第五次chapter5-6作业(10.25评讲)
设计递归算法将十进制正整数转成二进制并输出。 void convert(int x){ if(x1){ convert(x/2); coutx%2;} else coutx ;} 写递归算法,在长度为n的数组A中查找item,成功返回位序,失败返回-1 int find(int a[],int n,int item)//从后往前查找, {if (n=0)return -1;//如数组长度n小于或等于0,则失败 else if (a[n-1]==item)//如尾部元素为item,成功 return n-1; else return find(a,n-1,item); //否则,在长度为n-1的数组中继续用同样的方法进行查找 } 顺序表下删除第position个位置之后的k个元素的方法 template class List_entry Error_code ListList_entry :remove_k(int position,int k) { int j; if (position0 || k=0 || positon+kcount) return range_error; for (j=position+k;jcount;j++) entry[j-k]=entry[j]; count-=k; return success; } 2、逆置 (a)//顺序表下的逆置 template class List_entry Error_code ListList_entry :: reverse() { List_entry temp; for (int i=0,j=count-1;i=count/2-1;i++,j--) { temp=entry[i]; entry[i]=entry[j]; entry[j]=temp; } return success; } (b)//简单单链表的逆置,直接利用原表空间 template class List_entry Error_code ListList_entry :: reverse() { NodeList_entry *p,*q; if (count1){ p=head-next; head-next=NULL; while (p){ q=p-next; p-next=head; head=p; p=q; } } return success; } (c)//与线性表存储方案无关的逆置算法 template class List_entry Error_code ListList_entry :: reverse() { for (int i=0;isize();i++){ remove(i,item); insert(0,item); } return success; } template class List_entry Error_code ListList_entry :: reverse() { int i,j; List_entry itema,itemb; for (i=0,j=size()-1;ij;i++,j--) retrieve(i,itema); retrieve(j,itemb); replace(i,itemb); replace(j,itema); } (d)//简单单链表逆置递归算法 template class List_entry Error_code ListList_entry :: reverse() { head=rec_reverse(head); } template class List_entry NodeList_entry* ListList_entry :: rec_reverse(NodeList_entry *head) { if(head==null) return head; NodeList_entry *p=head-next; if(p==null) return head; else{ NodeList_entry *new_head=rec_reverse(p); p-next=head; head-next=null; return new_head; } } E6.1 E6,E7 Given the methods for lists described in this section, write functions to do each of the following tasks. Be sure to specify the preconditions and postcon
您可能关注的文档
最近下载
- 大麦EK318.操作手册.C01.220905.pdf
- 五马先生纪年.docx VIP
- 急救与心理技能(视频课)知到课后答案智慧树章节测试答案2025年春中南大学.docx VIP
- 应急救援员国家职业技能标准(2019年版).pdf VIP
- 场地设计作图题-一级建筑师场地设计(作图题)真题精选.docx VIP
- 小学环境教育:校园内水体污染调查与水质保护实践教学研究课题报告.docx
- 阿迪达斯(Adidas)品牌现状分析与二次增长战略规划.pptx
- 人教版七年级上册数学一元一次方程计算题及应用题.docx VIP
- 人教版2025八年级上册英语Unit3 same or different单元复习课件.pptx VIP
- 濒危古树评估与抢救保护技术规程.docx VIP
文档评论(0)