网站编程语言培训机构,建设网站建设安全培训平台,网线制作考核标准,深圳市招聘信息网站线性表的基本操作顺序存储(C语言)#include#include#include#define LIST_INIT_SIZE/*线性表存储空间初始分配量*/#define LISTINCREMENT/*线性表存储空间分配增量*/#define ok? 1#define OVERFLOW? -1#define false? 0typedef struct {?ElemType *elem;/*存储空间*/?int l…线性表的基本操作顺序存储(C语言)#include#include#include#define LIST_INIT_SIZE/*线性表存储空间初始分配量*/#define LISTINCREMENT/*线性表存储空间分配增量*/#define ok? 1#define OVERFLOW? -1#define false? 0typedef struct {?ElemType *elem;/*存储空间*/?int lenght;/*当前线性表长度*/?int? listsize;/*当前分配的存储容量*/}SqList;int InitList_Sq(SqList *L){? /*构建空线性表*/? L-elem(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));/*分配存储空间*/?if(!L-elem)exit(OVERFLOW);/*分配存储空间失败*/?L-lenght0; /*初始化线性表长度为0*/?L-listsizeLIST_INIT_SIZE;/*初始存储容量*/?return ok;}int LenghtList_Sq(SqList *L){/*求线性表长度*/? return L-lenght;}int DestroyList_Sq(SqList *L)??{?? /*销毁线性表*/?? free(L-elem);/*释放存储空间*/?? L-elemNULL;/*线性表中元素为0*/?? L-length0;/*线性表长度为0*/?? L-listsize0;/*存储空间为空*/?? return ok;?}int? ClearList(SqList *L)? {/*清零操作*/?? L-length0;/*线性表长度为0*/? return ok;}int? ListEmpty(SqList *L)? {? /*判空操作*/? if(L.length0)/*线性表长度为0*/?? return True;?else?return False;}int ?GetElem(SqList *L,int i,ElemType *e){?? /*得到第I 个元素的数据元素的值*/?? if(i1 || iL.length)?? return false;?? e*(L-elemi-1);/*取第i个元素并赋值给e*/?? return ok;}int LocateElem(SqList *L,ElemType e,void (*compare)(ElemType,ElemType)){? /*查找与E相等的元素的位置*/? ElemType *p;? i1;? while(iL-length !compare(*p,e))/*判断i所在位置*/? i;if(iL-length)return i;elsereturn 0;}int PriorElem(SqList *L,ElemType cur_e,ElemType pre_e)?{/*得到给出的数的前一个元素值*/? int i2;? ElemType *p;? pL-elem1;? while(iL-length !(*pcur_e))? i;? if(iL-length)? return false;else? {?? pre_e*--p;?? return OK;? }}?int NextElem(SqList L,ElemType pre_e,ElemType cur_e){? /* 得到后一个元素的值*/? int i1;? ElemType *p;?? pL-elem;? while(ilength !(*ppre_e))? i;? if(iL-length)? return false;else? {??? cur_e*p;??? return OK;? }}?int InsertElem(SqList *L,int i,ElemType e)?{? /*在第I个元素中插入一个值为E的元素*/? int newbase;? SqList *p,*q;?if(i1 || ilength1)/*判断i是否在线性表中*/?return ERROR;?if(L-lengthL-listsiz