最近在学习数据结构,看书写的代码(例题2-2)。在linux系统已实现。
有不当的地方欢迎指出,共同进步~~
#include <stdio.h>
#include <stdlib.h>
#define ERROR 0
#define OK 1
#define OVERFLOW -2
#define INIT_LIST_SIZE 50
#define LISTINCREMENT 10
#include <stdlib.h>
#define ERROR 0
#define OK 1
#define OVERFLOW -2
#define INIT_LIST_SIZE 50
#define LISTINCREMENT 10
typedef int ElemType;
typedef int Status;
typedef struct{
ElemType *elem;
int length;
int listsize;
}SqList;
Status InitList(SqList &L){ //初始化线性表。
L.elem = (ElemType *)malloc(INIT_LIST_SIZE*sizeof(ElemType)); //开辟内存空间。
if(!L.elem){
exit(OVERFLOW);
}
L.length = 0;
L.listsize = INIT_LIST_SIZE;
return OK;
}
L.elem = (ElemType *)malloc(INIT_LIST_SIZE*sizeof(ElemType)); //开辟内存空间。
if(!L.elem){
exit(OVERFLOW);
}
L.length = 0;
L.listsize = INIT_LIST_SIZE;
return OK;
}
Status InsertList(SqList &L, ElemType e){ &nb