/*
* @Author: Mr.Sen
* @LastEditTime: 2020-04-30 20:13:46
* @Website: https://449293786.site
* @原创代码,版权所有,转载请注明原作者
*/
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int value;
struct node *next;
}link_list;
link_list* creat_tail(int length)
{
//尾插法
link_list *head,*node,*tail;
head=(link_list*)malloc(sizeof(link_list));
tail=head;//如果节点数为零,那么头结点就是尾节点
while(length--)
{
node = (link_list*)malloc(sizeof(link_list));
scanf("%d",&node->value);
tail->next=node;
tail=node;
}
tail->next=NULL;
return head;
}
void print(link_list* head)
{
link_list *node=head;
while (node->next!=NULL)
{
node=node->next;
printf("->%d",node->value);
}
}
int main()
{
print(creat_tail(5));
return 0;
}
作者:NorthCity1984
出处:https://grimoire.cn/note/single-chain.html
版权:本文《单链表代码优化》版权归作者所有
转载:欢迎转载,但未经作者同意,必须保留此段声明;必须在文章中给出原文连接;否则必究法律责任
出处:https://grimoire.cn/note/single-chain.html
版权:本文《单链表代码优化》版权归作者所有
转载:欢迎转载,但未经作者同意,必须保留此段声明;必须在文章中给出原文连接;否则必究法律责任