欢迎来到天天文库
浏览记录
ID:50849184
大小:32.50 KB
页数:7页
时间:2020-03-15
《顺序存储结构线性表基本操作纯C语言实现.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、/////////////////////////////////////////////////////////////---------------------------------------------------------// 顺序存储结构线性表基本操作纯C语言实现//// asimpleexampleofSq_ListbyClanguage//// bywangweinoo1[PG]//---------
2、------------------------------------------------///////////////////////////////////////////////////////////#include#include//以下为函数运行结果状态代码#defineTRUE1#defineFALSE0#defineOK1#defineERROR0#defineINFEASIBLE-1#defineOVERFLOW-2#defineLI
3、ST_INIT_SIZE5 //线性表存储空间的初始分配量#defineLISTINCREMENT1 //线性表存储空间分配增量typedefintStatus;//函数类型,其值为为函数结果状态代码typedefintElemType;//假设数据元素为整型typedefstruct{ ElemType*elem;//存储空间基址 intlength;//当前长度 intlistsize;//当前分配的存储容量}Sqlist;//实现线性表的顺序存储结构的类型定义/*static*
4、/SqlistL;//为了引用方便,定义为全局变量/*static*/ElemTypeelement;StatusInitList(SqlistL);StatusDestroyList(SqlistL);StatusClearList(SqlistL);StatusListEmpty(SqlistL);StatusListLength(SqlistL);StatusGetElem(SqlistL,inti,ElemType*element);StatusLocationElem(SqlistL,
5、ElemTypeelement);StatusPriorElem(SqlistL,ElemTypecur_e,ElemType*pre_e);StatusNextElem(SqlistL,ElemTypecur_e,ElemType*next_e);StatusListInsert(SqlistL,inti,ElemTypee);StatusListDelet(SqlistL,inti,ElemTypee);/////////////////////////////////////////函数名
6、:InitList()//参数:SqListL//初始条件:无//功能:构造一个空线性表//返回值:存储分配失败:OVERFLOW// 存储分配成功:OK///////////////////////////////////////StatusInitList(SqlistL){ L.elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType)); if(L.elem==NULL) exit(OVERFLOW);
7、 else { L.length=0; L.listsize=LISTINCREMENT; returnOK; }}/////////////////////////////////////////函数名:DestroyList()//参数:SqListL//初始条件:线性表L已存在//功能:销毁线性表//返回值:L.elem==NULL:ERROR// L.elem!==NULL:OK///////////////////////////
8、////////////StatusDestroyList(SqlistL){ if(L.elem==NULL) returnERROR; else free(L.elem); returnOK;}/////////////////////////////////////////函数名:ClearList()//参数:SqListL//初始条件:线性表L已存在//功能:清空线性表//返回值:L.elem==NULL:ERROR// L.elem!=
此文档下载收益归作者所有