资源描述:
《表(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(