typedef struct ListElement{
int studid,numofcourses,postcode;
float gpa;
char firstname[NUM];
char lastname[NUM];
char deprt[NUM];
} ListElement;
typedef struct snode {
int key;
struct ListElement *data;
struct snode **forward;
} snode;
typedef struct skiplist {
int level;
struct snode *header;
struct snode *maxvalue;
} skiplist;
skiplist *skiplist_init(skiplist *list) {
int i;
snode *header = (snode *) malloc(sizeof(struct snode) + (sizeof(ListElement)));
snode *maxvalue = (snode *) malloc(sizeof(struct snode) + (sizeof(ListElement)));
list->header = header;
header->key = INT_MAX;
header->forward = (snode **) malloc(sizeof(snode*) * (SKIPLIST_MAX_LEVEL + 1) + (sizeof(ListElement***emphasized text***)));
for (i = 0; i <= SKIPLIST_MAX_LEVEL; i++) {
header->forward[i] = list->maxvalue;
}
list->level = 2;
return list;
}
我正在制作跳过列表并且我得到了分段错误。我认为我使用的是malloc错误,但由于我是新手,所以我不能单独使用它。 Segfault在其他函数插入中弹出,但我认为faut是在这部分代码中。