数据结构实验之链表三:链表的逆置

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_数据结构实验之链表三:链表的逆置的更多相关文章

  1. SDUT 3311 数据结构实验之串三:KMP应用

    数据结构实验之串三:KMP应用 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 有n个小朋友 ...

  2. SDUT 3347 数据结构实验之数组三:快速转置

    数据结构实验之数组三:快速转置 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 转置运算是一 ...

  3. SDUT OJ 数据结构实验之二叉树三:统计叶子数

    数据结构实验之二叉树三:统计叶子数 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descr ...

  4. SDUT OJ 数据结构实验之串三:KMP应用

    数据结构实验之串三:KMP应用 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...

  5. SDUT OJ 数据结构实验之排序三:bucket sort

    数据结构实验之排序三:bucket sort Time Limit: 250 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem D ...

  6. SDUT 3400 数据结构实验之排序三:bucket sort

    数据结构实验之排序三:bucket sort Time Limit: 150MS Memory Limit: 65536KB Submit Statistic Problem Description ...

  7. SDUT 3375 数据结构实验之查找三:树的种类统计

    数据结构实验之查找三:树的种类统计 Time Limit: 400MS Memory Limit: 65536KB Submit Statistic Problem Description 随着卫星成 ...

  8. SDUT 3342 数据结构实验之二叉树三:统计叶子数

    数据结构实验之二叉树三:统计叶子数 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 已知二叉 ...

  9. SDUT 2133 数据结构实验之栈三:后缀式求值

    数据结构实验之栈三:后缀式求值 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 对于一个基于二元运算符的后缀表示式(基本操作数都是 ...

  10. SDUT OJ 数据结构实验之链表三:链表的逆置

    数据结构实验之链表三:链表的逆置 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descri ...

随机推荐

  1. php传入参数

    项目中时常会使用php编写脚本,进行一些统计与批量更新的需求需要进行操作其中使用的方式主要是getopt函数,写法如下 <?php $opt = getopt('m:n:'); $value_m ...

  2. web端的兼容性测试

    目前主流的浏览器有:chrome.firefox.safari.IE edge.Opera等.其中IE edge ,Google浏览器 和firefox被称为现代浏览器. 浏览器排行榜2019年4月浏 ...

  3. MacBook 启用或停用 root 用户

    启用或停用 root 用户 选取苹果菜单 () >“系统偏好设置”,然后点按“用户与群组”(或“帐户”). 点按 ,然后输入管理员名称和密码. 点按“登录选项”. 点按“加入”(或“编辑”). ...

  4. Nginx负载均衡反向代理

    http{ upstream test.com { server 118.118.66.88:8080; } server { listen 80; server_name www.test.com; ...

  5. spring boot定时任务解析

    在SpringBoot中定时任务一般使用的是@Scheduled注解. @Scheduled 1.注解内容: @Target({ElementType.METHOD, ElementType.ANNO ...

  6. Leetcode641.Design Circular Deque设计循环双端队列

    设计实现双端队列. 你的实现需要支持以下操作: MyCircularDeque(k):构造函数,双端队列的大小为k. insertFront():将一个元素添加到双端队列头部. 如果操作成功返回 tr ...

  7. 交互题(apio2016Gap)

    题目链接   //Serene #include<algorithm> #include<iostream> #include<cstring> #include& ...

  8. linux 查看磁盘空间占用情况

    工作中有时被分配的测试机空间不大,经常遇到磁盘空间占满的情况.排查过程如下: 一.首先使用df -h 命令查看磁盘剩余空间,通过以下图看出/目录下的磁盘空间已经被占满. 二.进入根目录,因为最近常用的 ...

  9. Linux下下载安装jdk1.7和IDEA

    一.安装JDK1.7 准备: 到Oracle官网下载下载jdk1.7,参考博客 https://blog.csdn.net/H12KJGJ/article/details/79240984 官网地址: ...

  10. SDUT-3398_数据结构实验之排序一:一趟快排

    数据结构实验之排序一:一趟快排 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 给定N个长整型范围内的整数,要求输出以给 ...