单链表的尾插法(C语言实现)
标签:include nbsp load 尾插法 str bsp mic int 顺序
#include
#include
#includemalloc.h>
typedef struct LNode{
int data;
struct LNode* next;
}LNode,*LinkList;
LinkList List_TailInsert(LinkList &L,int n)
{
int x,i;
L = (LinkList)malloc(sizeof(LNode));
LNode *s , *r = L;
for(i=0;i)
{
s = (LNode*)malloc(sizeof(LNode));
printf("请输入第%d个数字:",i+1);
scanf("%d",&x);
s->data = x;
r->next = s;
r = s;
}
r->next = NULL;
return L;
}
int main()
{
LinkList L;
LNode *node;
int n;
printf("请输入链表节点数n:");
scanf("%d",&n);
List_TailInsert(L,n);
node = L->next;
printf("按照顺序输出链表的元素:\n");
while(node != NULL)
{
printf("%d ",node->data);
node = node->next;
}
printf("\n");
return 0;
}
单链表的尾插法(C语言实现)
标签:include nbsp load 尾插法 str bsp mic int 顺序
原文地址:https://www.cnblogs.com/Romantic-Chopin/p/13341353.html
评论