数据结构实验之链表四:有序链表的归并(SDUT 2119)
#include <bits/stdc++.h>
using namespace std;
struct node
{
int data;
struct node *next;
};
struct node *creat(int n)
{
struct node *head,*tail,*p;
head=(struct node*)malloc(sizeof(struct node));
head->next=NULL;
tail=head;
int i;
for(i=0;i<n;i++)
{
p=(struct node*)malloc(sizeof(struct node));
p->next=NULL;
scanf("%d",&p->data);
tail->next=p;
tail=p;
}
return head;
}
int main()
{
struct node *head,*head1,*head2,*p,*p1,*p2,*tail;
head=(struct node*)malloc(sizeof(struct node));
head->next=NULL;
tail=head;
int n,m;
scanf("%d %d",&n,&m);
head1=creat(n);
head2=creat(m);
p1=head1->next;
p2=head2->next;
free(head1);
free(head2);
while(p1&&p2)
{
if(p1->data<p2->data)
{
tail->next=p1;
tail=p1;
p1=p1->next;
tail->next=NULL;
}
else
{
tail->next=p2;
tail=p2;
p2=p2->next;
tail->next=NULL;
}
}
if(p1) tail->next=p1;
else tail->next=p2;
for(p=head->next;p!=NULL;p=p->next)
{
if(p==head->next) printf("%d",p->data);
else printf(" %d",p->data);
}
return 0;
}
数据结构实验之链表四:有序链表的归并(SDUT 2119)的更多相关文章
- 数据结构实验之排序四:寻找大富翁(SDUT 3401)
#include <stdio.h> #include <stdlib.h> #include <string.h> void Swap(int a[], int ...
- 数据结构实验之查找四:二分查找(SDUT 3376)
#include <stdio.h> #include <string.h> #include <stdlib.h> int a[1000005]; int fin ...
- SDUT OJ 数据结构实验之图论四:迷宫探索
数据结构实验之图论四:迷宫探索 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...
- SDUT OJ 数据结构实验之二叉树四:(先序中序)还原二叉树
数据结构实验之二叉树四:(先序中序)还原二叉树 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem ...
- SDUT OJ 数据结构实验之排序四:寻找大富翁
数据结构实验之排序四:寻找大富翁 Time Limit: 200 ms Memory Limit: 512 KiB Submit Statistic Discuss Problem Descripti ...
- SDUT 3401 数据结构实验之排序四:寻找大富翁.!
数据结构实验之排序四:寻找大富翁 Time Limit: 150MS Memory Limit: 512KB Submit Statistic Problem Description 2015胡润全球 ...
- SDUT 3376 数据结构实验之查找四:二分查找
数据结构实验之查找四:二分查找 Time Limit: 20MS Memory Limit: 65536KB Submit Statistic Problem Description 在一个给定的无重 ...
- SDUT 3361 数据结构实验之图论四:迷宫探索
数据结构实验之图论四:迷宫探索 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 有一个地下迷 ...
- SDUT 3343 数据结构实验之二叉树四:还原二叉树
数据结构实验之二叉树四:还原二叉树 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 给定一棵 ...
- SDUT-3376_数据结构实验之查找四:二分查找
数据结构实验之查找四:二分查找 Time Limit: 30 ms Memory Limit: 65536 KiB Problem Description 在一个给定的无重复元素的递增序列里,查找与给 ...
随机推荐
- 选择最佳策略:简单的方式和globals()
promos = [fidelity_promo, bulk_item_promo, large_order_promo] ➊ def best_promo(order): ➋ "" ...
- Spring 自定义Bean 实例获取
一.通过指定配置文件获取, 对于Web程序而言,我们启动spring容器是通过在web.xml文件中配置,这样相当于加载了两次spring容器 ApplicationContext ac = new ...
- MQTT协议探究(三)
1 回顾与本次目标 1.1 回顾 主题通配符 主题语义和用法 WireShark进行抓包分析了报文 报文分析: SUBSCRIBE--订阅主题 SUBACK--订阅确认 UNNSUBSCRIBE--取 ...
- php对象转换为数组的部分代码
function object_array($array){ if(is_object($array)){ $array = (array)$array; } if(is_array($array)) ...
- SqlServer学习之触发器
什么是触发器? 根据百度百科的解释,触发器是SqlServer提供给程序员和数据分析员来保证数据完整性的一种方法,它是与表事件相关的特殊的存储过程,他的执行不是有程序调用,也不是手工启动,而是由事件来 ...
- Idea+Maven部署打包JavaFX项目遇到的坑
用Idea写了一个JavaFX项目,创建artifacts,build artifacts,运行build出来的exe可执行文件时总是遇到 class not found的错误,如下图 一开始根据提示 ...
- Batch normalization简析
Batch normalization简析 What is batch normalization 资料来源:https://www.bilibili.com/video/av15997678/?p= ...
- luogu P5023 填数游戏
luogu loj 被这道题送退役了 题是挺有趣的,然而可能讨论比较麻烦,肝了2h 又自闭了,鉴于CSP在即,就只能先写个打表题解了 下面令\(n<m\),首先\(n=1\)时答案为\(2^m\ ...
- mysql tinyint(1) 在java中被转化为boolean
数据库表字段类型为:tinyint 长度为1 在java中对应的类型是boolean 查询时直接在页面展示成true或false 如果是2,3,4 这样的也是默认成true,非常不友好. 解决方案: ...
- linux终端c语言改变输出字体颜色
Linux下C改变输出字体颜色 例: #include int main() { printf("\033[31mThis is RED.\n\033[0m"); return 0 ...