数据结构与算法分析——c语言描述 练习3.15 答案
list.h
typedef int ElementType;
#define SpaceSize 100
#ifndef _Cursor_H
#define _Cursor_H
struct SelfAdjustRecord;
typedef struct SelfAdjustRecord* SelfAdjust;
typedef int PtrToNode;
typedef PtrToNode Position;
SelfAdjust creatList(int space);
Position Find(ElementType X, SelfAdjust L);
void Insert(ElementType X, SelfAdjust L);
#endif
list.c
#include"list.h"
#include<stdlib.h>
#include"fatal.h"
struct SelfAdjustRecord {
ElementType *arr;
int capacity;
int rearCur;
};
SelfAdjust creatList(int space) {
SelfAdjust s = malloc(sizeof(struct SelfAdjustRecord));
if (s == NULL)
Error("out of memory");
s->arr = malloc(sizeof(ElementType)*space);
if (s->arr == NULL)
Error("out of memory");
s->capacity = space;
s->rearCur = -1;
return