先上代码
#include <stdio.h>
#include <stdlib.h>
struct Node
{
int date;
struct Node* next;
};
struct Node* creat_link(struct Node *head)
{
head = (struct Node*)malloc(sizeof(struct Node));
head->next = NULL;//头结点不动
struct Node* tail = head;//尾节点先和头结点对齐
for (int i = 0; i < 10; i++)
{
struct Node* temp = (struct Node*)malloc(sizeof(struct Node)); //创建临时变量接收
temp->date = i;
temp->next = NULL; //先将next设为NULL
tail->next = temp; 尾结点指向创建的变量 建立联系
tail = temp; //更新tail
}
//head ->0->0->tail
//
return head;
}
void print(struct Node* head)
{
head=head->next;
while (head!= NULL)
{
printf("%d\n", head->date);
head = head->next;
}
}
int main()
{
struct Node* head;
head=creat_link(head);//初始化
print(head);
return 0;
}
05-03
2848
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-17
9818
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-14
1482
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交