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

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 <stdlib.h> struct node
{
int data;
struct node *next;
}; int main()
{
struct node *head, *tail, *p, *q;
head = (struct node *)malloc(sizeof(struct node));
head->next = NULL;
tail = head; int n;
while(scanf("%d",&n)&&n!=-1)
{
p = (struct node *)malloc(sizeof(struct node));
p->next = NULL;
p->data = n;
tail->next = p;
tail = p; } p = head->next;
head->next = NULL;
q = p->next;
while(p){
p->next = head->next;
head->next = p;
p = q;
if(q) q = q->next;
} p = head->next;
while(p->next){
printf("%d ",p->data);
p = p->next; } printf("%d\n",p->data);
return 0;
}

SDUT OJ 数据结构实验之链表三:链表的逆置的更多相关文章

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

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

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

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

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

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

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

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

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

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

  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  有疑问?点这里^_^ 题目描述 对于一个基于二元运算符的后缀表示式(基本操作数都是 ...

随机推荐

  1. A Look at the Razor View Engine in ASP.NET MVC

    The biggest architectural difference that exists between ASP.NET MVC and ASP.NET Web Forms is the ne ...

  2. 执行CUnit测试出错

    est/test_fifo.test: error while loading shared libraries: libcunit.so.1: cannot open shared object f ...

  3. Win10 linux子系统Ubuntu下显示图形界面

    转载 https://jingyan.baidu.com/article/ed2a5d1f98577809f6be17a3.html 打开终端界面,在这个窗口测试一下ls命令,无误. # 更新 sud ...

  4. 10.Execution failed with exit status: 3

    错误信息: insert overwrite table t_mobile_mid_use_p_tmp4_rcf select '201411' as month_id, a.prov_id, a.c ...

  5. 35.MID() 函数

    MID() 函数 MID() 函数 MID 函数用于从文本字段中提取字符. SQL MID() 语法 SELECT MID(column_name,start[,length]) FROM table ...

  6. activex打包

    http://www.cnblogs.com/weiwin/p/4493835.html activeX 打包   原文 http://www.docin.com/p-409284488.html C ...

  7. c# 获取非托管指针长度

    public List<string> GetPDFValues() { List<string> strs = new List<string>(); unsaf ...

  8. hrabs的数据库session的修改

    using System;using System.Data;using System.Collections;using System.Collections.Generic;using Syste ...

  9. 实践作业3:接到任务及思考DAY1

    今天,老师又布置了新的学习任务,关于白盒测试.感觉黑盒测试,我们用的比较多,白盒测试就相对陌生了.上课的时候老师虽然也进行了一定的点拨,外加我们学习了SPOC视频,但是并没有看到什么具体的项目,所以实 ...

  10. iOS play video

    iOS: How to use MPMoviePlayerController up vote6down votefavorite 3 I've created a blank project (iO ...