sdut 2118-数据结构实验之链表三:链表的逆置
2016-12-12 18:07
627 查看
Statistic Discuss
输入多个整数,以-1作为结束标志,顺序建立一个带头结点的单链表,之后对该单链表的数据进行逆置,并输出逆置后的单链表数据。
输入多个整数,以-1作为结束标志。
输出逆置后的单链表数据。
Example Input
不得使用数组。
在头插法的基础上稍稍改动即可
Problem Description
输入多个整数,以-1作为结束标志,顺序建立一个带头结点的单链表,之后对该单链表的数据进行逆置,并输出逆置后的单链表数据。
Input
输入多个整数,以-1作为结束标志。
Output
输出逆置后的单链表数据。Example Input
12 56 4 6 55 15 33 62 -1
Example Output
62 33 15 55 6 4 56 12
Hint
不得使用数组。
Author
在头插法的基础上稍稍改动即可01 | #include <iostream> |
02 | #include<stdio.h> |
03 | #include <stdlib.h> |
04 | using namespace std; |
05 | struct node |
06 |
07 | { |
08 |
09 | int date; |
10 | struct node *next; |
11 | }; |
12 | int main() |
13 | { |
14 | int n; |
15 | struct node *L,*s,*r; |
16 | L=( struct node*) malloc ( sizeof ( struct node)); |
17 |
18 | L->next=NULL; |
19 | r=L; |
20 |
21 |
22 | while ( scanf ( "%d" ,&n)&&n!=-1) |
23 | { |
24 | s=( struct node*) malloc ( sizeof ( struct node)); |
25 | s->date=n; |
26 | s->next=r->next; |
27 | r->next=s; |
28 |
29 | } |
30 | s=L->next; |
31 | while (s!=NULL) |
32 | { |
33 | printf ( "%d " ,s->date); |
34 | s=s->next; |
35 | } |
36 | return 0; |
37 | } |
38 |
39 |
40 | /*************************************************** |
41 | User name: YT1558503112东野 |
42 | Result: Accepted |
43 | Take time: 0ms |
44 | Take Memory: 148KB |
45 | Submit time: 2016-12-12 18:01:14 |
46 | ****************************************************/ |
相关文章推荐
- sdut 2117 -数据结构实验之链表二:逆序建立链表
- 排序算法-希尔排序
- 排序算法-插入排序
- 排序算法-选择排序
- sdut 2116—数据结构实验之链表一:顺序建立链表
- 数据结构实验之排序五:归并求逆序数
- js 数据结构与算法 更新ing
- 模拟哈希(开放地址法)
- 古老的火车问题
- 数据结构期末总结
- Java数据结构和算法-链表(3-有序链表)
- 动态树 LCT(Link-Cut-Tree)--入门教程
- 数据结构之图(存储结构、遍历)
- java数据结构与算法之递归思维(让我们更通俗地理解递归)
- 数据结构——哈希表
- kdtree&knn
- BZOJ 1146 二分+链剖+线段树+treap
- 数据结构——二叉树
- 算法与数据结构(十四) 堆排序 (Swift 3.0版)
- 常用的数据结构(data structure)