链表初始化报错了
这是源程序:#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<string.h>
#define Maxsize 50
typedef struct phone {
char name[20];
char tel[15];
} ph;
struct node {
ph data;
struct node *next;
} Linklist;
int LinkInit(Linklist *L) {
if( NULL == L) { //若未定义实参则初始化失败
return FAILURE;
}
(*L) = (Linklist *) malloc( sizeof( Linklist) * 1);
(*L)->next = NULL;
return SUCCESS;
}
void createlistF(Linklist *&L,ph a[],int n) {
Linklist *s;
int i;
for(i=0; i<n; i++) {
s=(Linklist *)malloc(sizeof(Linklist));
s->data=a[i];
s->next=L->next;
L->next=s;
}
}
bool createlistF1(Linklist *&L,ph a,int n) {
int j=0;
Linklist *p=L,*s;
while(j<n-1&&p!=NULL) {
j++;
p=p->next;
}
if(p==NULL) return false;
else {
s=(Linklist *)malloc(sizeof(Linklist));
s->data=a;
s->next=p->next;
p->next=s;
return true;
}
}
bool ListDelete(Linklist*&L,int i, ph &x) {
int j=0;
Linklist *p=L,*q;
while(j<i-1&&p!=NULL) {
j++;
p=p->next;
}
if(p==NULL) return false;
else {
q=p->next;
if(q==NULL) return false;
x=q->data;
p->next=q->next;
free(q);
return true;
}
}
void Find(Linklist *Link) {
if( NULL == Link) {
printf("error 3\n");
sleep(1);
exit(1);
}
Linklist *current = Link; // current 指向目标节点的前一个
Linklist *target; // target 记录找到的目标节点
char name[20];
printf("Press name:");
scanf("%s", name);
printf("Find result:\n");
printf("\t%-20s %-20s\n", "Name", "Telephone number");
while( current->next != NULL ) {
target = current->next;
if( 0 == strcmp(target->recoder.name, name)) {
printf("\t%-20s %-20s\n", target->recoder.name, target->recoder.tel);
printf("Find success.\n");
sleep(1);
return;
}
current = current->next;
}
printf("Can't find %s's infomation", name);
fflush(stdout);
}
void DispList(Linklist *L) {
Linklist *p=L->next;
int i=1;
printf("\n -------------通讯录---------------\n");
while(p!=NULL) {
printf(" %d. %-20s%-10s\n",i,p->data.name,p->data.tel);
p=p->next;
i++;
}
printf(" -------------------------------\n");
}
void DestroyList(Linklist *&L) {
L=(Linklist *)malloc(sizeof(Linklist));
L->next=NULL;
}
void menu1() {
printf(" ------------------------------\n");
printf(" 手机通讯录的应用(单链表)\n");
printf(" ------------------------------\n");
printf(" 1.添加联系人信息\n");
printf(" 2.显示联系人信息\n");
printf(" 3.删除联系人信息\n");
printf(" 4.查找联系人信息\n");
printf(" 5.销毁通讯录\n");
printf(" 6.已退出!!\n");
printf(" ------------------------------\n\n");
}
int main() {
Linklist *h;
int i;
int flag=1;
int j;
ph s[17]= {"阿 光","13901210583","鲍大志","13001180515","高 倩","13001251186","陆 坚","13003133982","苏 瑾","13005166737",
"蒋莉勤","13501245184","龚 湘","13501262620","李程元","13500002222","大 山","13503018291","刘 凯","13520004921","韩文静","13436789011",
"黄 珊","13001141590","李圆圆","13001251186","李小婉","13001126879","何国华","18979788888","马 柯","13501204259","含 笑","13601008282"
};
ph x;
menu1();
InitList(h);
createlistF(h,s,17);
DispList(h);
while(flag==1) {
printf("请选择:");
scanf("%d",&j);
switch(j) {
case 1:
printf("请输入联系人姓名和电话号:");
scanf("%s %s",x.name,x.tel);
printf("请输入插入的位置:");
scanf("%d",&i);
fflush(stdin);
printf("\n");
createlistF1(h,x,i);
break;
case 2:
DispList(h);
break;
case 3:
printf("请输入删除的位置:");
scanf("%d",&i);
ListDelete(h,i,x);
break;
case 4:
Find(L);
break;
case 5:
DestroyList(h);
printf("通讯录已销毁\n");
break;
case 6:
flag=0;
printf("\n 不再输入记录,退出!!\n\n");
break;
}
}
return 0;
}
结果运行的时候报错了
23 24 C:\Users\23080\Desktop\代码源.cpp [Error] 'L' was not declared in this scope
23 27 C:\Users\23080\Desktop\代码源.cpp [Error] expected ',' or ';' before '{' token
这个要怎么改啊