数据结构——链表之逆序建立链表
来源:互联网 发布:禁止外资参与网络出版 编辑:程序博客网 时间:2024/05/21 06:24
数据结构实验之链表二:逆序建立链表
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic
Problem Description
输入整数个数N,再输入N个整数,按照这些整数输入的相反顺序建立单链表,并依次遍历输出单链表的数据。
Input
第一行输入整数N;;
第二行依次输入N个整数,逆序建立单链表。
第二行依次输入N个整数,逆序建立单链表。
Output
依次输出单链表所存放的数据。
Example Input
1011 3 5 27 9 12 43 16 84 22
Example Output
22 84 16 43 12 9 27 5 3 11
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 *p;
11
int
i;
12
head->next=NULL;
13
for
(i=1;i<=n;i++)
14
{
15
p=(
struct
node*)
malloc
(
sizeof
(
struct
node));
16
scanf
(
"%d"
,&p->data);
17
p->next=head->next;
18
head->next=p;
19
}
20
return
(head);
21
}
22
struct
node *show(
struct
node *head)
23
{
24
struct
node *p;
25
p=(
struct
node*)
malloc
(
sizeof
(
struct
node));
26
p=head->next;
27
while
(p)
28
{
29
printf
(
"%d "
,p->data);
30
p=p->next;
31
}
32
return
(head);
33
}
34
int
main()
35
{
36
int
n;
37
struct
node *head;
38
head=(
struct
node*)
malloc
(
sizeof
(
struct
node));
39
scanf
(
"%d"
,&n);
40
build(head,n);
41
show(head);
42
return
0;
43
}
44
45
46
/***************************************************
47
User name: jk160618郭衣鹏
48
Result: Accepted
49
Take time: 0ms
50
Take Memory: 148KB
51
Submit time: 2017-10-06 17:33:22
52
****************************************************/
阅读全文
0 0
- 数据结构——链表之逆序建立链表
- 数据结构实验之链表二:逆序建立链表
- 数据结构实验之链表二:逆序建立链表
- 数据结构实验之链表二:逆序建立链表
- 数据结构实验之链表二:逆序建立链表
- SDUTOJ 2117 数据结构实验之链表二:逆序建立链表
- 数据结构实验之链表二:逆序建立链表
- 数据结构实验之链表二:逆序建立链表
- 【2117】数据结构实验之链表二:逆序建立链表
- 数据结构实验之链表二:逆序建立链表
- 数据结构实验之链表二:逆序建立链表
- 数据结构实验之链表二:逆序建立链表
- SDUT 2117 数据结构实验之链表二:逆序建立链表
- 数据结构实验之链表二:逆序建立链表
- OJ 数据结构实验之链表二:逆序建立链表
- 数据结构实验之链表二:逆序建立链表
- 数据结构实验之链表二:逆序建立链表
- 数据结构实验之链表二:逆序建立链表
- t.xml文件中的Activity属性android:name必须和工程src目录下的相关类名保持一致
- 用自己的数据完成“分类”
- 什么是MyBatis
- 内存移动:memmove原理模拟实现
- 决策树算法之ID3
- 数据结构——链表之逆序建立链表
- (84)温度单位的转换工具(方法的使用)
- Linux系统下用find命令查找最近修改过的文件
- JVM内存区域划分
- Amazon Dynamo架构分析(一)
- 年底阅读计划
- 列表生成器笔记(Python)
- shiro 返回 json
- Spring入门(AOP API,ProxyFactoryBean其三)