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

第6章作业(含补充).doc

  1. 1、本文档共7页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
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() { if (!empty()) for (int i=1;isize();i++){ remove(i,item); insert(0,item); } return success; } (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; } } 3.join two ordered list in a List, Error_code Join(List a_list,List b_list,List c_list) example : a_list=(1,3,5,7,9) b_list=(2,4,7,10,13) After the joint,c_list=(1,2,3,4,5,7,7,9,10,13) template class List_entry Error_code Join(List List_entry a_list, ListList_entry b_list, List List_entry c_list) { int i,j,k; c_list.clear(); i=0;j=0;k=0; while (ia_list.size() || jb_list.size()) if (i=a_list.size())//a表已到达表尾 {b_list.retrieve(j++,item_b); if (c_list.insert(k++,item_b)==overflow) return overflow ; } else if (j=b_list.size())//b表已到达表尾 { a_list.retrieve(i++,item_a); if (c_list.insert(k++,item_a)==overflow) return overflow ; } else//a,b两表都未到表尾,则将较小的元素插入到c表中。 { a_list.retrieve(

文档评论(0)

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

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

1亿VIP精品文档

相关文档