博客
关于我
两个递增有序链表合并成递减排序
阅读量:317 次
发布时间:2019-03-04

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

1.注意临时指针还是用来保存指针值,不要用来指结点

#include 
#include
typedef struct LNode{ int data; struct LNode* next;}LNode,*LinkList;LinkList CreateList(){ LinkList L; L = (LinkList)malloc(sizeof(LNode)); L->next = NULL; LNode *q = L; LNode *p; int x; scanf("%d",&x); while(x != 999) { p = (struct LNode *)malloc(sizeof(LNode)); p->data = x; p->next = NULL; q->next = p; q = p; scanf("%d",&x); } return L;}void main(){ LinkList a = (LinkList)malloc(sizeof(LNode)); LinkList b = (LinkList)malloc(sizeof(LNode)); a = CreateList(); b = CreateList(); LinkList c = (LinkList)malloc(sizeof(LNode)); c->next = NULL; LNode *p = a->next; LNode *q = b->next; LNode *y; while(p != NULL && q != NULL) { if(p->data <= q->data) { y = p->next; p->next = c->next; c->next = p; p = y; } if(p->data > q->data) { y = q->next; q->next = c->next; c->next = q; q = y; } } //ex if(q) p = q; while(p != NULL) { y = p->next; p->next = c->next; c->next = p; p = y; } y = c->next; while(y != NULL) { printf("%d ",y->data); y = y->next; }}

 

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

你可能感兴趣的文章
netty2---服务端和客户端
查看>>
【Flink】Flink 2023 Flink易用性和稳定性在Shopee的优化-视频笔记
查看>>
Netty5.x 和3.x、4.x的区别及注意事项(官方翻译)
查看>>
netty——bytebuf的创建、内存分配与池化、组成、扩容规则、写入读取、内存回收、零拷贝
查看>>
netty——Channl的常用方法、ChannelFuture、CloseFuture
查看>>
netty——EventLoop概念、处理普通任务定时任务、处理io事件、EventLoopGroup
查看>>
netty——Future和Promise的使用 线程间的通信
查看>>
netty——Handler和pipeline
查看>>
Vue输出HTML
查看>>
netty——黏包半包的解决方案、滑动窗口的概念
查看>>
Netty中Http客户端、服务端的编解码器
查看>>
Netty中使用WebSocket实现服务端与客户端的长连接通信发送消息
查看>>
Netty中实现多客户端连接与通信-以实现聊天室群聊功能为例(附代码下载)
查看>>
Netty中的组件是怎么交互的?
查看>>
Netty中集成Protobuf实现Java对象数据传递
查看>>
netty之 定长数据流处理数据粘包问题
查看>>
Netty事件注册机制深入解析
查看>>
netty代理
查看>>
Netty入门使用
查看>>
netty入门,入门代码执行流程,netty主要组件的理解
查看>>