typedef struct stu
{
long stuID; //学号
char stuname[10]; //名字
char stusex; //性别
DATE birthday; //生日
int score[4]; //4科分数
float aver; //平均分
}STU;
typedef struct node
{
STU stu;
struct node* next; //指向下一个节点的指针
}NODE;
NODE* head = NULL; //
Whether line
15 defines a header pointer or a header node, see shipin's definition of a header node, see the article is a header pointer
0 Answer
is not completely correct. In this code, although a new node is also created and its pointer field is set to NULL, this is not how the header node is created. It is simply used to create the first node in an empty linked list and use it as the head node of the list.
To create a header, insert a new node before the header pointer points to it. This new node serves as the header, and its data field can be any value, but the pointer field must point to where the header pointer points to in order to ensure the connectivity of the entire list.
Here is sample code to create a header node and insert it into the header of a linked list:
NODE* head = NULL; // 头指针初始化为NULL
// 创建头结点
NODE* newnode = (NODE*)malloc(sizeof(NODE));
newnode->next = head;
// 将头指针指向头结点
head = newnode;
creates a newnode, newnode, and sets its pointer field to where the head of the header pointer points. The header is then created by pointing the head of the header pointer to the newnode newnode.
Line 15 defines a header pointer, not a header node. A header pointer is a pointer to the head of a list, and a header node is an actual node of the head of a list, usually used to avoid special treatment of a header pointer when the list is empty. In this code snippet, the header pointer head has a value of NULL, indicating that the list is empty and therefore no header is needed. If you need to insert a new node into the header of the list, you need to create a new node as the header and point the header pointer to it.
这家伙很懒,什么都没留下...