资源描述:
《数据结构课设代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、-程序如下:#include#include#include#include#include#include#includeusingnamespacestd;enumError_code{success,fail,range_error,underflow,overflow,fatal,not_present,duplicate_error,entry_inserted,entry_found,internal_error}
2、;//enumkind{cigarette,water,gum,beer,bread};templatestructNode{stringkind1;Node_entryprice;Node_entryshelf;Node*next;Node();Node(stringkind_1,Node_entryprice2,Node_entryshelf2,Node*link);};templateNode::Node(){nex
3、t=NULL;}templateNode::Node(stringkind_1,Node_entryprice2,Node_entryshelf2,Node*link=NULL){kind1=kind_1;price=price2;shelf=shelf2;next=link;}template.---classList{public:Error_codeinsert(List&list,conststring&kind_1,constList_
4、entry&price2,constList_entry&shelf2);Error_coderemove(List&list,string&kind_1,List_entry&price2,List_entry&shelf2);Error_codereplace(List&list,conststring&kind_1,constList_entry&price2,constList_entry&shelf2);Error_coderetrieve(List&list,string&kind_1,List_entry&price2,List_entry&sh
5、elf2)const;voidsort();List();intsize()const;boolfull()const;boolempty()const;voidclear();voidtraverse(void(*visit)(List_entry&));~List();List(constList©);voidoperator=(constList©);voidsavedate(List&list);voidloaddate(List&list)
6、;protected:intcount;Node*head;Node*set_position(intposition)const;};templateError_codeList::insert(List&list,conststring&kind_1,constList_entry&price2,constList_entry&shelf2){intposition=list.size();if(position<0
7、
8、position>count)r
9、eturnfail;Node*new_node,*previous,*following;if(position>0){previous=set_position(position-1);following=previous->next;}elsefollowing=head;new_node=newNode(kind_1,price2,shelf2,following);if(new_node==NULL)returnoverflow;.---if(position==0)head=new_node;elsep
10、revious->next=new_n