欢迎来到天天文库
浏览记录
ID:40247159
大小:674.50 KB
页数:106页
时间:2019-07-29
《数据结构算法——Visual C++ 6.0程序集 第1章》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、数据结构算法VisualC++6.0程序集侯识忠等编著中国水利水电出版社第一章顺序存储结构的表、堆栈和队列1、0线性表的数组表示和实现//线性表的类定义linelist1.h#defineMaxListSize20#defineEQUAL1typedefstructSTU{charname[10];charstuno[10];intage;intscore;}ElemType;classList{private://线性表的数组表示ElemTypeelem[MaxListSize];intlength;intMaxSize;public://初始化顺序表voidinit(List**L,in
2、tms);//删除顺序表voidDestroyList(List&L){free(&L);}//将顺序表置为空表voidClearList(){length=0;}//判断顺序表是否为空表boolListEmpty(){returnlength==0;}//判断顺序表是否为满boolListFull(){returnlength==MaxSize;}//决定返回表中元素pre_e的前驱ElemTypePriorElem(ElemTypecur_e,ElemType&pre_e);//决定返回表中元素next_e的后继ElemTypeNextElem(ElemTypecur_e,ElemTyp
3、e&next_e);//从线性表中删除表头、表尾或等于给定值的元素boolListDelete(int,ElemType&e);//遍历顺序表voidListTraverse();//返回顺序表的长度intListLength();//获取顺序表中第i个元素voidGetElem(int,ElemType*);//判断顺序表两元素是否相等boolEqualList(ElemType*,ElemType*);//判断顺序表两元素是否不等boolLess_EqualList(ElemType*,ElemType*);//顺序表的查找算法boolLocateElem(ElemType,int);/
4、/更新线性表中的给定元素boolUpdateList(ElemType&e,ElemType);//顺序表的合并算法voidMergeList(List*,List*);//顺序表的插入算法boolListInsert(int,ElemType&);//顺序表的联合算法voidUnionList(List*,List*);//对线性表按升序或降序输出voidprintlist(int);};//线性表的实现linelist1.cpp#include"linelist1.h"voidList::init(List**L,intms){*L=(List*)malloc(sizeof(List))
5、;(*L)->length=0;(*L)->MaxSize=ms;}intList::ListLength(){returnlength;}ElemTypeList::PriorElem(ElemTypecur_e,ElemType&pre_e){for(inti=0;i6、;i0){//删除表头元素e=elem[0];for(i=1;i7、/删除值为e的元素for(i=0;i=length)returnfalse;elsee=elem[i];for(j=i+1;j
6、;i0){//删除表头元素e=elem[0];for(i=1;i7、/删除值为e的元素for(i=0;i=length)returnfalse;elsee=elem[i];for(j=i+1;j
7、/删除值为e的元素for(i=0;i=length)returnfalse;elsee=elem[i];for(j=i+1;j
此文档下载收益归作者所有