#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include <string.h> #include<stdlib.h> typedef struct _link { int val; struct val* next; }Link; Link* Build() { int val; Link* head =NULL, * tail = NULL, *cur = NULL;//头指针,尾指针,当前指针 while (scanf("%d", &val)) { cur = (Link*)malloc(sizeof(Link));//创建当前节点//为当前节点赋值,next指针指向空 cur->val = val; cur->next = NULL; if (head == NULL)//判断是否头节点为空 { head = cur; tail = cur;//头尾指针均指向当前节点 } else { //尾节点指向当前节点,更新尾节点 tail->next = cur; tail = cur; } } return head; }
标签:cur,val,建立,next,链表,Link,NULL,节点 From: https://www.cnblogs.com/young2478/p/17347126.html