sdut 2117 -数据结构实验之链表二:逆序建立链表
来源:互联网 发布:容声和美菱哪个好 知乎 编辑:程序博客网 时间:2024/06/06 13:18
Problem Description
输入整数个数N,再输入N个整数,按照这些整数输入的相反顺序建立单链表,并依次遍历输出单链表的数据。
Input
第一行输入整数N;;
第二行依次输入N个整数,逆序建立单链表。
第二行依次输入N个整数,逆序建立单链表。
Output
依次输出单链表所存放的数据。
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 <iostream>
02
#include<stdio.h>
03
#include <stdlib.h>
04
05
using
namespace
std;
06
struct
node
07
08
{
09
10
int
date;
11
struct
node *next;
12
};
13
int
main()
14
{
15
int
i,n;
16
struct
node *L,*s,*r;
17
L=(
struct
node*)
malloc
(
sizeof
(
struct
node));
18
19
L->next=NULL;
20
r=L;
21
22
cin>>n;
23
for
(i=0;i<n;i++)
24
{
25
26
s=(
struct
node*)
malloc
(
sizeof
(
struct
node));
27
scanf
(
"%d"
,&s->date);
28
s->next=r->next;
29
r->next=s;
30
31
32
}
33
34
s=L->next;
35
while
(s!=NULL)
36
{
37
printf
(
"%d "
,s->date);
38
s=s->next;
39
}
40
return
0;
41
}
42
43
44
/***************************************************
45
User name: YT1558503112东野
46
Result: Accepted
47
Take time: 0ms
48
Take Memory: 160KB
49
Submit time: 2016-12-12 17:36:05
50
****************************************************/
01
#include <iostream>
02
#include<stdio.h>
03
#include <stdlib.h>
04
05
using
namespace
std;
06
struct
node
07
08
{
09
10
int
date;
11
struct
node *next;
12
};
13
int
main()
14
{
15
int
i,n;
16
struct
node *L,*s,*r;
17
L=(
struct
node*)
malloc
(
sizeof
(
struct
node));
18
19
L->next=NULL;
20
r=L;
21
22
cin>>n;
23
for
(i=0;i<n;i++)
24
{
25
26
s=(
struct
node*)
malloc
(
sizeof
(
struct
node));
27
scanf
(
"%d"
,&s->date);
28
s->next=r->next;
29
r->next=s;
30
31
32
}
33
34
s=L->next;
35
while
(s!=NULL)
36
{
37
printf
(
"%d "
,s->date);
38
s=s->next;
39
}
40
return
0;
41
}
42
43
44
/***************************************************
45
User name: YT1558503112东野
46
Result: Accepted
47
Take time: 0ms
48
Take Memory: 160KB
49
Submit time: 2016-12-12 17:36:05
50
****************************************************/
0 0
- SDUT 2117 数据结构实验之链表二:逆序建立链表
- sdut 2117 -数据结构实验之链表二:逆序建立链表
- SDUT 2117数据结构实验之链表二:逆序建立链表
- SDUT 2117-数据结构实验之链表二:逆序建立链表
- 数据结构实验之链表二:逆序建立链表 (sdut oj)
- SDUT _2117 数据结构实验之链表二:逆序建立链表
- [SDUT](2117)数据结构实验之链表二:逆序建立链表 ---链式存储(线性表)
- 数据结构实验之链表二:逆序建立链表 (SDUT 2117)
- sdut.acm2012级《程序设计基础Ⅱ)》_链表 数据结构实验之链表二:逆序建立链表
- SDUTOJ 2117 数据结构实验之链表二:逆序建立链表
- 【2117】数据结构实验之链表二:逆序建立链表
- 【2117】数据结构实验之链表二:逆序建立链表
- 2117数据结构实验之链表二:逆序建立链表
- 2117数据结构实验之链表二:逆序建立链表
- 2117 数据结构实验之链表二:逆序建立链表
- 数据结构实验之链表二:逆序建立链表
- 数据结构实验之链表二:逆序建立链表
- 数据结构实验之链表二:逆序建立链表
- 坑【5】Java隐式转型
- webStorm绑定Tomcat
- Linux查看CPU和内存使用情况
- 最全IDC数据中心知识讲解(一)
- 字符串 比较 避免 null pointer exception
- sdut 2117 -数据结构实验之链表二:逆序建立链表
- tomcat无法启动 ClassNotFoundException org.springframework.web.context.ContextLoaderListener
- java mail发送邮件
- C#中的Math.Round使用的"四舍五入"法
- wxWidgets-3.0.2 Compile and Install (cc)
- 如何将vector 和 string 传递给 类C的API
- Centos服务器下网站做301重定向
- BPM制造业解决方案
- Ajax学习第一节_Ajax入门