谁帮我看一下,这段代码哪里出错了
#include<stdio.h>
#include<stdlib.h>
typedef int ElemType;
typedef struct LNode
{ ElemType data;
struct LNode *next;
}LNode,*LinkList;
void InitList(LinkList L){
L=(LinkList)malloc(sizeof(LNode));
if(!L)
printf("初始化失败!");
L->next=NULL;}
void CreateList(LinkList L){
int i,n,num; LNode *pnew;
printf("请你输入链表中的元素的个数:"); scanf("%d",&n);
for(i=0;i<n;i++)
{
pnew=(LinkList)malloc(sizeof(LNode)); printf("\n第%d个元素为: ",i+1); scanf("%d",&num);
pnew->data=num;
pnew->next=L->next;
L->next=pnew;
}}
int ListTraverse(LinkList L,void(*vi)(ElemType)){ LinkList p;
p=L->next;
while(p) {
vi(p->data);
p=p->next;
} printf("\n");}void print(ElemType c){ printf("%d\t",c);
}
int main()
{
LNode *L;
InitList(L);
CreateList(L);
ListTraverse(L,print);
}
#include<stdio.h>
#include<stdlib.h>
typedef int ElemType;
typedef struct LNode
{ ElemType data;
struct LNode *next;
}LNode,*LinkList;
void InitList(LinkList L){
L=(LinkList)malloc(sizeof(LNode));
if(!L)
printf("初始化失败!");
L->next=NULL;}
void CreateList(LinkList L){
int i,n,num; LNode *pnew;
printf("请你输入链表中的元素的个数:"); scanf("%d",&n);
for(i=0;i<n;i++)
{
pnew=(LinkList)malloc(sizeof(LNode)); printf("\n第%d个元素为: ",i+1); scanf("%d",&num);
pnew->data=num;
pnew->next=L->next;
L->next=pnew;
}}
int ListTraverse(LinkList L,void(*vi)(ElemType)){ LinkList p;
p=L->next;
while(p) {
vi(p->data);
p=p->next;
} printf("\n");}void print(ElemType c){ printf("%d\t",c);
}
int main()
{
LNode *L;
InitList(L);
CreateList(L);
ListTraverse(L,print);
}