有关动态链表创建,只有部分代码不理解,求高手帮忙
不明白的是链表创建部分的头指针与第一个节点LINK *create_list()
{
LINK *h,*r,*s;
h=(LINK*)malloc(sizeof(LINK));
r=h;
r->next=h; //这个地方r与h相等,含义是什么?
char ch=getchar();
..............
顺便解释一下LINK *create_list() 这种函数调用方式
程序代码:#include <stdio.h>
#include<malloc.h>
typedef struct Node
{
char data;
struct Node *next;
}LINK;
LINK *create_list()
{
LINK *h,*r,*s;
h=(LINK*)malloc(sizeof(LINK));
r=h;
r->next=h;
char ch=getchar();
while(ch!='\n')
{
s=(LINK*)malloc(sizeof(LINK));
s->data=ch;
r->next=s;
r=s;
ch=getchar();
}
r->next=NULL;
return h;
}
void print_list(LINK *h)
{
LINK *p;
p=h->next;
if(p==NULL)
printf("链表为空");
else
while(p!=NULL)
{
printf("%c",p->data);
p=p->next;
}
}
void main()
{
LINK *head;
head=create_list();
printf("The list is under line:\n");
print_list(head);
getchar();
}
[ 本帖最后由 sanjianfei 于 2012-3-23 18:24 编辑 ]









