表(Lists)和字符串

表(Lists)和字符串

ID:39624238

大小:35.00 KB

页数:7页

时间:2019-07-07

表(Lists)和字符串_第1页
表(Lists)和字符串_第2页
表(Lists)和字符串_第3页
表(Lists)和字符串_第4页
表(Lists)和字符串_第5页
资源描述:

《表(Lists)和字符串》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、一、定义:Theinsertions,deletionsandretrievalcanoccuredatanypointofthelist.二、实现:****utility.h:#include#include#include#include#includeenumError_code{success,fail,range_error,underflow,overflow,fatal,not_present,duplicate_error,entry_inserted,entr

2、y_found,internal_error};顺序实现:******list.h:#include"utility.h"constintmax_list=1000;templateclassList{public://methodsoftheListADTList();intsize()const;boolfull()const;boolempty()const;voidclear();voidtraverse(void(*visit)(List_entry&));Error_coderetrieve(intposition,List_en

3、try&x)const;Error_codereplace(intposition,constList_entry&x);Error_coderemove(intposition,List_entry&x);Error_codeinsert(intposition,constList_entry&x);protected://datamembersforacontiguouslistimplementationintcount;List_entryentry[max_list];};templateList::List

4、(){count=0;}templatevoidList::clear(){count=0;}templateintList::size()const{returncount;}templateboolList::empty()const{returncount<=0;}templateboolList::full()const{returncou

5、nt>=max_list;}templatevoidList::traverse(void(*visit)(List_entry&)){for(inti=0;iError_codeList::insert(intposition,constList_entry&x){if(full())returnoverflow;if(position<0

6、

7、position>count)retur

8、nrange_error;for(inti=count-1;i>=position;i--)entry[i+1]=entry[i];entry[position]=x;count++;returnsuccess;}templateError_codeList::retrieve(intposition,List_entry&x)const{if(position<0

9、

10、position>=count)returnrange_error;x=entry[position];returnsuccess;}template<

11、classList_entry>Error_codeList::replace(intposition,constList_entry&x){if(position<0

12、

13、position>=count)returnrange_error;entry[position]=x;returnsuccess;}templateError_codeList::remove(intposition,List_entry&x){if(

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。