数据结构——链表之顺序建立链表
来源:互联网 发布:ssm商城源码 编辑:程序博客网 时间:2024/06/02 05:07
数据结构实验之链表一:顺序建立链表
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic
Problem Description
输入N个整数,按照输入的顺序建立单链表存储,并遍历所建立的单链表,输出这些数据。
Input
第一行输入整数的个数N;
第二行依次输入每个整数。
第二行依次输入每个整数。
Output
输出这组整数。
Example Input
812 56 4 6 55 15 33 62
Example Output
12 56 4 6 55 15 33 62
Hint
01
#include <stdio.h>
02
#include <stdlib.h>
03
struct
node
04
{
05
int
data;
06
struct
node *next;
07
};
08
struct
node *build(
struct
node *head,
int
n)
09
{
10
struct
node *tail,*p;
11
int
i;
12
head->next=NULL;
13
tail=head;
14
for
(i=1;i<=n;i++)
15
{
16
p=(
struct
node*)
malloc
(
sizeof
(
struct
node));
17
scanf
(
"%d"
,&p->data);
18
p->next=NULL;
19
tail->next=p;
20
tail=p;
21
}
22
return
(head);
23
}
24
struct
node *show(
struct
node *head)
25
{
26
struct
node *p;
27
p=(
struct
node*)
malloc
(
sizeof
(
struct
node));
28
p=head->next;
29
while
(p)
30
{
31
printf
(
"%d "
,p->data);
32
p=p->next;
33
}
34
return
(head);
35
}
36
int
main()
37
{
38
int
n;
39
struct
node *head;
40
head=(
struct
node*)
malloc
(
sizeof
(
struct
node));
41
scanf
(
"%d"
,&n);
42
build(head,n);
43
show(head);
44
return
0;
45
}
46
47
48
/***************************************************
49
User name: jk160618郭衣鹏
50
Result: Accepted
51
Take time: 0ms
52
Take Memory: 176KB
53
Submit time: 2017-10-06 17:27:30
54
****************************************************/
阅读全文
0 0
- 数据结构——链表之顺序建立链表
- sdut 2116—数据结构实验之链表一:顺序建立链表
- 数据结构实验之链表一:顺序建立链表
- 数据结构实验之链表一:顺序建立链表
- 数据结构实验之链表一:顺序建立链表
- 数据结构实验之链表一:顺序建立链表
- SDUTOJ 2116 数据结构实验之链表一:顺序建立链表
- 数据结构实验之链表一:顺序建立链表
- 数据结构实验之链表一:顺序建立链表
- 【2116】数据结构实验之链表一:顺序建立链表
- 数据结构实验之链表一:顺序建立链表
- 数据结构实验之链表一:顺序建立链表
- SDUTOJ 2116 数据结构实验之链表一:顺序建立链表
- 数据结构实验之链表一:顺序建立链表
- SDUT 2116 数据结构实验之链表一:顺序建立链表
- 数据结构实验之链表一:顺序建立链表
- 数据结构实验之链表一:顺序建立链表
- 数据结构实验之链表一:顺序建立链表
- Linux之静态IP的配置
- 2017 10 06 NOIP2017模拟赛
- 硬件电路设计基础:三极管(3)
- react学习文档
- 【干货】PS图像修复与修饰工具用法
- 数据结构——链表之顺序建立链表
- 数据结构与算法之图
- 更换x210的uboot的logo
- Java语言处理环境
- Hibernate多对多的小案例
- [Android UI]基础组件的学习——ToggleButton的使用及样式修改
- govendor 使用命令
- HDU5521 Meeting (最短路)
- Error: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: