数据结构实验之链表三:链表的逆置 (SDUT 2118)
来源:互联网 发布:python和java待遇 编辑:程序博客网 时间:2024/05/26 05:53
数据结构实验之链表三:链表的逆置Time Limit: 1000MS Memory limit: 65536K
题目描述
输入多个整数,以-1作为结束标志,顺序建立一个带头结点的单链表,之后对该单链表的数据进行逆置,并输出逆置后的单链表数据。
输入
输入多个整数,以-1作为结束标志。
输出
输出逆置后的单链表数据。
示例输入
12 56 4 6 55 15 33 62 -1
示例输出
62 33 15 55 6 4 56 12
提示
不得使用数组。
来源
示例程序
#include<stdio.h>#include<stdlib.h>struct node{ int data ; struct node *next ;} ;struct node *creat(){ struct node *head, *tail, *p ; int num ; head = ( struct node *)malloc(sizeof(struct node)) ; head -> next = NULL ; tail = head ; while(~scanf("%d",&num)&&num!=-1) { p = (struct node *)malloc(sizeof(struct node)) ; p->data=num; p->next=NULL ; tail -> next=p ; tail=p; } return (head) ;}struct node *reverse(struct node *head){ struct node *p, *q ; p = head->next ; head->next=NULL ; q = p->next ; while (p!=NULL) { p->next=head->next ; head -> next = p ; p = q ; if(q!=NULL) q = q->next ; } return (head);}int main(){ struct node *head, *p ; head = creat() ; head = reverse(head) ; p = head->next; while(p->next!=NULL) { printf("%d ", p->data); p = p->next; } printf("%d\n", p->data); return 0;}
0 0
- 数据结构实验之链表三:链表的逆置 (SDUT 2118)
- 【2118】数据结构实验之链表三:链表的逆置 (SDUT)
- sdut 2118-数据结构实验之链表三:链表的逆置
- SDUT 2118数据结构实验之链表三:链表的逆置
- SDUT 2118-数据结构实验之链表三:链表的逆置
- 数据结构实验之链表三:链表的逆置 (sdut oj)
- sdut.acm2012级《程序设计基础Ⅱ)》_链表 数据结构实验之链表三:链表的逆置
- 【2118】数据结构实验之链表三:链表的逆置
- 【2118】数据结构实验之链表三:链表的逆置
- 2118数据结构实验之链表三:链表的逆置
- 2118数据结构实验之链表三:链表的逆置
- 2118数据结构实验之链表三:链表的逆置
- 2118 数据结构实验之链表三:链表的逆置
- SDUT 2116 数据结构实验之链表一:顺序建立链表
- SDUT 2117 数据结构实验之链表二:逆序建立链表
- SDUT 2116----数据结构实验之链表一:顺序建立链表
- sdut oj2054 数据结构实验之链表九:双向链表
- <sdut-ACM>数据结构实验之链表一:顺序建立链表
- Eclipse + ADT(包括NDK Plugin) + CDT 搭建Android NDK开发环境
- go语言的new和make
- 10、Objective-C语法之NSArray和NSMutableArray
- Codeforces Round #252 (Div. 2)-C,D
- Linux下安装Nginx详细图解教程
- 数据结构实验之链表三:链表的逆置 (SDUT 2118)
- 11、Objective-C语法之NSDictionary和NSMutableDictionary
- java的抽象类和抽象方法(注意查看如何调用抽象类中的非抽象方法)
- 闲暇时间看了下DHT网络
- JS中单引号/双引号以及外部js引入的一些问题
- shell 内建命令 exec
- 遍历二叉树的各种操作(非递归遍历)
- 综合思路养成记之税法怎么学
- 企业业务流程管理软件功能简介