线性链表顺序存储结构(C语言实现)
线性链表顺序存储结构(C语言实现)/*需要有的内容:#include#include#include typedef int ElemType;*/
/*sqlist.txt*/typedef struct list{ int Length; int ListSize; ElemType *elem; }sqlist;int InitList( sqlist *l){/*对sqlist *l进行初始化*/ l->Length=0; l->ListSize=4; l->elem=(ElemType *)malloc(4*sizeof(ElemType)); if(!l->elem) return error; else return OK;}int DestroyList(sqlist *l){/*毁坏sqlist *l的结构*/ free(l);}int ClearList(sqlist *l){ if(l->Length){ free(l->elem); l->Length=0; l->elem=(ElemType*)malloc((l->ListSize)*sizeof(ElemType)); } return OK;}int ListEmpty(sqlist l){/*判断sqlist *l是否为空*/ if(l.Length==0) return Ture; else return Flase;}int ListLength(sqlist l){/*求出sqlist l的长度*/ int temp=0; temp=l.Length; return temp;}int GetElem(sqlist l,int i,ElemType *e){/*如果sqlist *l不是空,取出sqlist *l的第一个元素,并将其传给e*/ if(i<1||i>l.ListSize) return error; else *e=l.elem[i-1];}int LocateElem(sqlist l,ElemType e,int compare(ElemType ,ElemType )){ if(compare(l.elem[0],e)==1) return OK; else return Flase;}ElemType PriorElem(sqlist l,ElemType cur_e,ElemType *pre_e){/* 判断sqlist *l中是否有元素 cur_e, 并将其前驱传给pre_e */ int i,k=0; ElemType *p; p=NULL; if(!l.Length||l.elem[0]==cur_e) return Flase; pre_e=(ElemType*)malloc((l.Length)*sizeof(ElemType)); for(i=1;i