#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node*next;
};
struct node * creat(int n)
{
struct node *head,*tail,*p;
int i;
head=(struct node*)malloc(sizeof(struct node));
head ->next=NULL;
tail=head;
for(i=1;i<=n;i++)
{
p=(struct node *)malloc(sizeof(struct node));
scanf("%d",&p->data);
p->next=NULL;
tail->next=p;
tail=p;
}
return (head);
}
void print(struct node * head)
{
struct node *p;
p=head->next;
while(p!=NULL)
{
printf("%d",p->data);
if(p->next!=NULL)
{
printf(" ");
}
else
{
printf("\n");
}
p=p->next;
}
}
int main()
{
int N;
struct node * head;
scanf("%d",&N);
head=creat(N);
print(head);
return 0;
}
数据结构之顺序建链表
原创mb61037a3723f67 ©著作权
©著作权归作者所有:来自51CTO博客作者mb61037a3723f67的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:师--链表的结点插入
下一篇:买文具
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
【数据结构】链式家族的成员——循环链表与静态链表
【数据结构】第二章——线性表(8)详细介绍了循环链表与静态链表的相关内容……
数据结构 C语言 循环链表 静态链表 -
【数据结构】C语言实现顺序栈
【数据结构】第三章——栈、队列和数组详细介绍通过C语言实现顺序栈
数据结构 C语言 顺序栈 -
数据结构实验之链表一:顺序建立链表
题目描述输入N个整数,按照输入的顺序建立单链表存储,并遍历所建立的
编程 c语言 #include 链表 i++