指向结构体的指针作为函数形参
下面程序中CreateList_L函数前两个是对的,第三个是错的,谁能解释一下这3个有啥区别,第三个为什么错了?
程序代码:#include<stdio.h>
#include<stdlib.h>
typedef struct LNode{
int data;
struct LNode *next;
}LNode,*LinkList;
void CreateList_L(LinkList &L,int n){
//逆序输入n个元素的值,建立带头结点的单链线性表L
int i;
LNode *p;
L=(LinkList )malloc(sizeof(LNode));
L->next=NULL;
for(i=n;i>0;i--){
p=(LinkList )malloc(sizeof(LNode));
printf("请输入");
scanf("%d",&p->data);
p->next=L->next;
L->next=p;
}
}
void CreateList_L(LinkList *L,int n){
//逆序输入n个元素的值,建立带头结点的单链线性表L
int i;
LNode *p;
(*L)=(LinkList )malloc(sizeof(LNode));
(*L)->next=NULL;
for(i=n;i>0;i--){
p=(LinkList )malloc(sizeof(LNode));
printf("请输入");
scanf("%d",&p->data);
p->next=(*L)->next;
(*L)->next=p;
}
}
void CreateList_L(LNode *L,int n){
//逆序输入n个元素的值,建立带头结点的单链线性表L
int i;
LNode *p;
L=(LinkList )malloc(sizeof(LNode));
L->next=NULL;
for(i=n;i>0;i--){
p=(LinkList )malloc(sizeof(LNode));
printf("请输入");
scanf("%d",&p->data);
p->next=L->next;
L->next=p;
}
}
void main(){
LinkList L=NULL,p=NULL;
int n;
printf("输入元素数目:");
scanf("%d",&n);
printf("\n逆序创建链式表Lb\n");
CreateList_L( L, n);
p=L;
printf ( "\n链式表Lb内容为:\n" );
while(p->next!=NULL)
{
p=p->next;
printf("%d ",p->data);
}
}







