关于初始化单链表的问题?
arfu 2000-09-06 09:23:00 typedef struct
{
char name[20];
int age;
}elemtype
struct slnode
{
elemtype data;
struct slnode * next;
}
//下面定义单链表结点结构
typedef struct slnode
{
elemtype data;
struct slnode* next;
}slnodetype;
//初始化代码
int initiate(slnodetype * * h) //指向指针的指针
{
if((*h=(slnodetype *)malloc(sizeof(slnodetype )))==NULL)
return 0;
(* h)->noext =NULL;
return 1;
}
// 书上说,h是单链表的头指针,如果定义为slnodetype *h;将无法带回函数中建立的头指针值。
我不懂,觉得不需用**h, 仅定义为* h 就可。
我把他改为
int initiate(slnodetype * h)
{
if((h=(slnodetype *)malloc(sizeof(slnodetype )))==NULL)
return 0;
(h)->noext =NULL;
return 1;
}
各位觉得有什么问题?? 各位高手讲解???
谢谢帮助