各位大佬,请教一下链表
比如下面一段代码,结点是由数据部和指针部组成的,在第十七行中定义了首元结点,但是为什么要让指针部作为一个空指针?#include<stdio.h>
#include<stdlib.h>
struct Link {
char data;
Link *pointer;
}link;
Link *link_build(int g);
int main() {
Link*a1 = link_build(6);
system("pause");
return 0;
}
Link *link_build(int g) {
Link *head = (Link*)malloc(sizeof(Link));
Link *head_p = head;
for (int i = 0; i < g; i++) {
Link *node = (Link*)malloc(sizeof(Link));
node->pointer = NULL;
node->data = i;
head_p->pointer = node;
head_p = head_p->pointer;
}
return head;
}