顺序存储结构线性表本操作_纯C语言实现.docVIP

  • 3
  • 0
  • 约6.65千字
  • 约 7页
  • 2016-06-30 发布于贵州
  • 举报

顺序存储结构线性表本操作_纯C语言实现.doc

顺序存储结构线性表本操作_纯C语言实现

/////////////////////////////////////////////////////////// //--------------------------------------------------------- //??????????? 顺序存储结构线性表基本操作 纯C语言实现 // //??????????? a simple example of Sq_List by C language // //??????????????????? by wangweinoo1[PG] //--------------------------------------------------------- /////////////////////////////////////////////////////////// #include stdio.h #include stdlib.h //以下为函数运行结果状态代码 #define TRUE 1 #define FALSE 0 #define OK 1 #define ERROR 0 #define INFEASIBLE -1 #define OVERFLOW -2 #define LIST_INIT_SIZE 5? //线性表存储空间的初始分配量 #define LISTINCREMENT 1? //线性表存储空间分配增量 typedef int Status; //函数类型,其值为为函数结果状态代码 typedef int ElemType; //假设数据元素为整型 typedef struct { ??? ElemType *elem; //存储空间基址 ??? int length; //当前长度 ??? int listsize; //当前分配的存储容量 }Sqlist; //实现线性表的顺序存储结构的类型定义 /*static*/ Sqlist L;//为了引用方便,定义为全局变量 /*static*/ ElemType element; Status InitList(Sqlist L); Status DestroyList(Sqlist L); Status ClearList(Sqlist L); Status ListEmpty(Sqlist L); Status ListLength(Sqlist L); Status GetElem(Sqlist L,int i, ElemType *element); Status LocationElem(Sqlist L,ElemType element); Status PriorElem(Sqlist L,ElemType cur_e,ElemType *pre_e); Status NextElem(Sqlist L,ElemType cur_e,ElemType *next_e); Status ListInsert(Sqlist L,int i,ElemType e); Status ListDelet(Sqlist L,int i,ElemType e); /////////////////////////////////////// //函数名:InitList() //参数:SqList L //初始条件:无 //功能:构造一个空线性表 //返回值:存储分配失败:OVERFLOW //??????? 存储分配成功:OK /////////////////////////////////////// Status InitList(Sqlist L) { ??? L.elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType)); ??? if(L.elem==NULL) ??????? exit(OVERFLOW); ??? else ??? { ??????? L.length=0; ??????? L.listsize=LISTINCREMENT; ??????? return OK; ??? } } /////////////////////////////////////// //函数名:DestroyList() //参数:SqList L //初始条件:线性表L已存在 //功能:销毁线性表 //返回值:L.elem==NULL:ERROR //??????? L.elem!==NULL:OK /////////////////////////////////////// Status DestroyList(Sqlist L) { ???

文档评论(0)

1亿VIP精品文档

相关文档