预览加载中,请您耐心等待几秒...
1/7
2/7
3/7
4/7
5/7
6/7
7/7

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

#include<stdio.h> #include<stdlib.h> #include<Define.h> #define TRUE 1 #define FALSE 0 #define OK 1 #define ERROR 0 #define INFEASIBLE -1 #define OVERFLOW -2 typedef int Status; typedef intElemType; #define LIST_INIT_SIZE 100 #define LISTINCREMENT 10 typedefstruct { ElemType*elem; intlength; intlistsize; }SqList; StatusInitList_Sq(SqList*L);//构造空的线性表 voidDestroyList_Sq(SqList*L); //销毁一个线性表 voidClearList_Sq(SqList*L); //将L置为空表 StatusListEmpty_Sq(SqListL); //空表返回TRUE StatusListLength_Sq(SqListL); //返回元素个数 StatusGetElem_Sq(SqListL,inti,ElemType*e); //用e返回第i个元素算法2.2中使用 StatusLocateElem_Sq(SqListL,ElemTypee,Status(*compare)(ElemType,ElemType)); //在L中找到一个值与e满足compare()的元素的位序 StatusPriorElem_Sq(SqListL,ElemTypecur_e,ElemType*pre_e); //用pre_e返回cur_e的前驱 StatusNextElem_Sq(SqListL,ElemTypecur_e,ElemType*next_e); //用next_e返回cur_e的后继 StatusListInsert_Sq(SqList*L,inti,ElemTypee); //在第i位插入新的元素e StatusListDelete_Sq(SqList*L,inti,ElemType*e); //删除第i个元素用e返回 //算法2.3 StatusInitList_Sq(SqList*L)//构造空的线性表 { L->elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType)); if(!L->elem) { printf("构造失败!\n"); exit(OVERFLOW); } L->length=0; L->listsize=LIST_INIT_SIZE; printf("构造成功!\n"); returnOK; } voidDestroyList_Sq(SqList*L) //销毁一个线性表 { if(L->elem!=NULL) { free(L->elem); L->elem=NULL; L->length=0; L->listsize=0; printf("已销毁线性表!\n"); } } voidClearList_Sq(SqList*L) //将L置为空表 { if(L->elem!=NULL) { L->length=0; printf("已将L置为空表!\n"); } } StatusListEmpty_Sq(SqListL) //空表返回TRUE { if(L.elem!=NULL) { if(L.length==0) { printf("是空表\n"); returnTRUE; } else { printf("不是空表\n"); returnFALSE; } } else { exit(ERROR); } } StatusListLength_Sq(SqListL) //返回元素个数 { if(L.elem!=NULL) { returnL.length; } else { returnERROR; } } StatusGetElem_Sq(SqListL,inti,ElemType*e) //用e返回第i个元素算法2.2中使用 { if(ListEmpty_Sq(L)) { printf("为空表!\n"); returnERROR; } if(i<1||i>L.length) {