
两个有序链表序列的交集(c语言)
发布日期:2021-05-06 03:53:29
浏览次数:14
分类:技术文章
本文共 1249 字,大约阅读时间需要 4 分钟。
两个有序链表序列的交集
题目
答案
#include#include struct Array{ int data; struct Array *next;};int main(){ struct Array *head,*head1,*pa,*pb,*head2,*p,*temp; head1=(struct Array *)malloc(sizeof(struct Array)); head1->next=NULL; p=head1; int t; while(1) { scanf("%d",&t); if(t==-1) break; else { temp=(struct Array *)malloc(sizeof(struct Array)); temp->data=t; temp->next=NULL; p->next=temp; p=p->next; } } head2=(struct Array *)malloc(sizeof(struct Array)); head2->next=NULL; p=head2; while(1) { scanf("%d",&t); if(t==-1) break; else { temp=(struct Array *)malloc(sizeof(struct Array)); temp->data=t; temp->next=NULL; p->next=temp; p=p->next; } } head=(struct Array *)malloc(sizeof(struct Array)); head->next=NULL; p=head; pa=head1->next; pb=head2->next; while(pa&&pb) { if(pa->data==pb->data) { p->next=pa; p=p->next; pa=pa->next; pb=pb->next; } else if(pa->data data) pa=pa->next; else if(pa->data>pb->data) pb=pb->next; } p->next=NULL; int flag=0; if(head->next==NULL) { printf("NULL"); return 0; } while(head->next) { if(flag==0) { printf("%d",head->next->data); flag=1; } else printf(" %d",head->next->data); head=head->next; }}
发表评论
最新留言
路过按个爪印,很不错,赞一个!
[***.219.124.196]2025年03月29日 02时41分46秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
多位水仙花数-python(出现运行超时?不妨用减法计算)
2019-03-03
地下迷宫探索(后两个测试点无法通过?这里有你想要的答案)
2019-03-03
城市间紧急救援(dijkstra算法)
2019-03-03
小白看完都会了!阿里云大师深入拆解Java虚拟机,看完这一篇你就懂了
2019-03-03
【IT之路】FAQ-Hibernate报错:表不存在
2019-03-03
VBA之正则表达式(19)-- 相对引用转绝对引用
2019-03-03
巧用VBA统一数字单位
2019-03-03
Transpose实现数组行列转置的限制
2019-03-03
VBA中数组72变(随心所欲复制)
2019-03-03
[Golang]golang中自动锁的实现
2019-03-03
用float/double作为中转类型的“雷区”
2019-03-03
golang中interface的一些语法缺陷的改进
2019-03-03
vue-router路由 学习笔记
2019-03-03
数据结构与算法之栈
2019-03-03
【数据库】第七章课后题
2019-03-03
第四章 串、数组和广义表 —— BF算法和KMP算法
2019-03-03
[选拔赛1]花园(矩阵快速幂),JM的月亮神树(最短路),保护出题人(斜率优化)
2019-03-03
DLA:一种深度网络特征融合方法
2019-03-03
leetcode114(二叉树展开为链表)
2019-03-03
java —— this 关键字
2019-03-03