博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
数据结构实验之链表三:链表的逆置
阅读量:3948 次
发布时间:2019-05-24

本文共 1002 字,大约阅读时间需要 3 分钟。

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

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

转载地址:http://hwhwi.baihongyu.com/

你可能感兴趣的文章
android如何实现:当开启图案解锁时,取消滑动解锁
查看>>
Providing Ancestral and Temporal Navigation 设计高效的应用导航
查看>>
Putting it All Together: Wireframing the Example App 把APP例子用线框图圈起来
查看>>
Implementing Lateral Navigation 实现横向导航
查看>>
Implementing Ancestral Navigation 实现原始导航
查看>>
Implementing Temporal Navigation 实现时间导航
查看>>
Responding to Touch Events 响应触摸事件
查看>>
Defining and Launching the Query 定义和启动查询
查看>>
Handling the Results 处理结果
查看>>
如何内置iperf到手机中
查看>>
如何adb shell进入ctia模式
查看>>
Contacts Provider 联系人存储
查看>>
android 图库播放幻灯片时灭屏再亮屏显示keyguard
查看>>
android 图库语言更新
查看>>
android camera拍照/录像后查看图片/视频并删除所有内容后自动回到camera预览界面
查看>>
android 图库中对非mp4格式的视频去掉"修剪"功能选项
查看>>
how to disable watchdog
查看>>
android SDIO error导致wifi无法打开或者连接热点异常的问题
查看>>
android USB如何修改Serial Number or SN?
查看>>
android 用svn管理的版本编译出来有问题
查看>>