#include"stdio.h"
#include"stdlib.h"
#include"stdbool.h"
typedef int ElemType;
typedef struct LNode{
ElemType data;
struct LNode *next;
}LinkList;
void CreateListH(LinkList *L,ElemType a[],int n){
LinkList *s;
int i;
L = (LinkList*)malloc(sizeof(LinkList));
L->next = NULL;
for(i = 0;i < n;i++){
s = (LinkList*)malloc(sizeof(LinkList));
s->data = a[i];
s->next = L->next;
L->next = s;
}
}
void CreateListR(LinkList *L,ElemType a[],int n){
LinkList *s,*r;
int i;
L = (LinkList*)malloc(sizeof(LinkList));
r = L;
// 分配新结点并用尾插法链接
for(i = 0;i < n;i++){
s = (LinkList*)malloc(sizeof(LinkList));
s->data = a[i];
r->next = s;
r = s;
}
r->next = NULL;
}
void InitList(LinkList *L){
L = (LinkList*)malloc(sizeof(LinkList));
L->next = NULL;
}
void DestroyList(LinkList *L){
// pre指向L,即头结点;p指向头结点的下一个结点,即首元结点
LinkList *pre = L,*p = L->next;
// 类似放鞭炮,前面响完后面响
while (p != NULL){
free(pre);
pre = p;
p = p->next;
}
free(pre);
}
bool EmptyList(LinkList *L){
// TRUE:空 FALSE:非空
return(L->next == NULL);
}
int ListLength(LinkList *L){
int n = 0;
LinkList *p = L;
while(p->next != NULL){
n++;
p = p->next;
}
return (n);
}
void DisplayList(LinkList *L){
LinkList *p = L->next;
while (p != NULL){
printf("%d ",p->data);
p = p->next;
}
printf("\n");
}
int GetElem(LinkList *L,int i,ElemType e){
int j = 0;
LinkList *p = L;
while (j<i && p!=NULL){
j++;
p = p->next;
}
if(p == NULL){
return 0;
// return false;
}else{
e = p->data;
printf("Get %d's elem is:%d",i,e);
return e;
// return true;
}
}
int main(){
LinkList *L;
int a[] = {1,3,5,7,9};
CreateListH(L,a,3);
DisplayList(L);
}
图片是断电调试提示的错误,请懂的兄弟帮我解答一下。