SDUT-2118_数据结构实验之链表三:链表的逆置
数据结构实验之链表三:链表的逆置
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
输入多个整数,以-1作为结束标志,顺序建立一个带头结点的单链表,之后对该单链表的数据进行逆置,并输出逆置后的单链表数据。
Input
输入多个整数,以-1作为结束标志。
Output
输出逆置后的单链表数据。
Sample Input
12 56 4 6 55 15 33 62 -1
Sample Output
62 33 15 55 6 4 56 12
Hint
不得使用数组。
跟链表的插入差不多,将节点断开重新插入到头结点后面。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct node
{
int data;
struct node *next;
}link;
link *newlink()
{
link *t;
t = (link*)malloc(sizeof(link));
t->next = NULL;
return t;
}
link *create()
{
link *head,*p,*q;
int x;
head = newlink();
p = head;
while(scanf("%d",&x))
{
if(x==-1)
break;
q = newlink();
q->data = x;
q->next = NULL;
p->next = q;
p = q;
}
return head;
}
link *change(link *head)
{
link *p,*q;
p = head->next;
head->next = NULL;
while(p)
{
q = p;
p = p->next;
q->next = head->next;
head->next = q;
}
return head;
}
void show(link *head)
{
link *p;
p = head->next;
while(p)
{
if(p->next==NULL)
printf("%d\n",p->data);
else
printf("%d ",p->data);
p = p->next;
}
}
int main()
{
link *head;
head = create();
head = change(head);
show(head);
return 0;
}
SDUT-2118_数据结构实验之链表三:链表的逆置的更多相关文章
- SDUT 3311 数据结构实验之串三:KMP应用
数据结构实验之串三:KMP应用 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 有n个小朋友 ...
- SDUT 3347 数据结构实验之数组三:快速转置
数据结构实验之数组三:快速转置 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 转置运算是一 ...
- SDUT OJ 数据结构实验之二叉树三:统计叶子数
数据结构实验之二叉树三:统计叶子数 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descr ...
- SDUT OJ 数据结构实验之串三:KMP应用
数据结构实验之串三:KMP应用 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...
- SDUT OJ 数据结构实验之排序三:bucket sort
数据结构实验之排序三:bucket sort Time Limit: 250 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem D ...
- SDUT 3400 数据结构实验之排序三:bucket sort
数据结构实验之排序三:bucket sort Time Limit: 150MS Memory Limit: 65536KB Submit Statistic Problem Description ...
- SDUT 3375 数据结构实验之查找三:树的种类统计
数据结构实验之查找三:树的种类统计 Time Limit: 400MS Memory Limit: 65536KB Submit Statistic Problem Description 随着卫星成 ...
- SDUT 3342 数据结构实验之二叉树三:统计叶子数
数据结构实验之二叉树三:统计叶子数 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 已知二叉 ...
- SDUT 2133 数据结构实验之栈三:后缀式求值
数据结构实验之栈三:后缀式求值 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 对于一个基于二元运算符的后缀表示式(基本操作数都是 ...
- SDUT OJ 数据结构实验之链表三:链表的逆置
数据结构实验之链表三:链表的逆置 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descri ...
随机推荐
- 10.30NOIP集训总结
1.第一眼是优先队列,然后发现n很大. 然后再观察一下,发现就可以二分,然后套用莫比乌斯反演里面的分块. 然后卡卡常就过了. 发现一个严肃的事情,就是说long long相除(相模)都会占用很多时间. ...
- Caused by: java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal
学习htmlutil发现报错 完整的引入 <!-- 引入htmlunit --> <dependency> <groupId>net.sourceforge.htm ...
- scala的插值器
Scala 为我们提供了三种字符串插值的方式,分别是 s, f 和 raw.它们都是定义在 StringContext 中的方法. s 字符串插值器 val a = 2println(s"小 ...
- Cross-site scripting(XSS)
https://en.wikipedia.org/wiki/Cross-site_scripting Definition Cross-site scripting (XSS) is a type o ...
- 公司mysql问题三
数据库连接不上,解决方案: # 加在绿框?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
- Spring MVC JSON自己定义类型转换
版权声明:版权归博主全部.转载请带上本文链接.联系方式:abel533@gmail.com https://blog.csdn.net/isea533/article/details/28625071 ...
- MySQL.之 一行内容转换多行
MySQL.之 一行内容转换多行 描述: 将一行记录中的某一列值(值格式:数据之间用英文逗号隔开),将这一数据转换成多行. 例如:表 cds_var 中的 cds_value 中的数据格式:多个id之 ...
- day38 21-今天的内容总结
以前我们在web层里面去调Service再在Service里面去调DAO是一路new过去的,在web层里面new Service,然后在Service里面new DAO.每次你都需要主动去找这个对象. ...
- COOKIE与SESSION的详解
cookie与session的小例子: 包含cookie记住登录名,session防止用户非法登录2个例子: 问我拿吧,这个下载连接挂了 描述 cookie过程描述 网站为了辨别用户身份.进行 ses ...
- 解决Dynamic Web Module 3.0 requires Java 1.6 or newer.问题
在项目的pom.xml的<build></build>标签中增加: <plugins> <plugin> <gro ...