SDUT OJ 数据结构实验之链表四:有序链表的归并
数据结构实验之链表四:有序链表的归并
Problem Description
Input
第二行依次输入M个有序的整数;
第三行依次输入N个有序的整数。
Output
Sample Input
6 5
1 23 26 45 66 99
14 21 28 50 100
Sample Output
1 14 21 23 26 28 45 50 66 99 100
Hint
拆开重建,连节点前先比较,找出较小的一个作为节点;
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node *next;
};
int main()
{
struct node *head, *tail, *p, *q, *head2;
head = (struct node *)malloc(sizeof(struct node));
head->next = NULL;
head2 = (struct node *)malloc(sizeof(struct node));
head2->next = NULL;
int i, m, n;
scanf("%d %d",&m,&n);
tail = head;
for(i=0; i<m; i++){
p = (struct node *)malloc(sizeof(struct node));
scanf("%d",&p->data);
p->next = NULL;
tail->next = p;
tail = p;
}
tail = head2;
for(i=0; i<n; i++){
p = (struct node *)malloc(sizeof(struct node));
scanf("%d",&p->data);
p->next = NULL;
tail->next = p;
tail = p;
}
p = head->next;
q = head2->next;
tail = head;
while(p&&q){
if(p->data<q->data){
tail->next = p;
tail = p;
p = p->next;
}
else{
tail->next = q;
tail = q;
q = q->next;
}
}
while(p){
tail->next = p;
tail = p;
p = p->next;
}
while(q){
tail->next = q;
tail = q;
q = q->next;
}
p = head->next;
while(p->next){
printf("%d ",p->data);
p = p->next;
} printf("%d\n",p->data);
return 0;
}
SDUT OJ 数据结构实验之链表四:有序链表的归并的更多相关文章
- 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 OJ 数据结构实验之链表六:有序链表的建立
数据结构实验之链表六:有序链表的建立 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Desc ...
- SDUT OJ 数据结构实验之链表九:双向链表
数据结构实验之链表九:双向链表 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...
随机推荐
- python中shuffleSplit()函数
参数: n : int 数据集中的元素总数. n_iter : int (default 10) 重新洗牌和分裂迭代次数. test_size : float (default 0.1), int, ...
- sql2012新的系统函数&分析函数
一 .系统函数 1.字符串类函数:不用判断类型和NULL的字符串连接CONCAT函数 SQL Server本来对字符串的连接很简单,直接使用“+”号,但是需要注意两个问题,一是必须类型都是字符串类型, ...
- 03-nginx虚拟主机配置
不想用kill命令控制nginx也行,但是其他命令没有信号的命令丰富.重读配置文件不用重启nginx(软重启).完全可以使用stop(强制退出).quick(优雅退出).reopen(重新打开日志). ...
- PHP Curl请求Https接口
在请求http的时候只需要 file_get_contents("http://www.sojson.com/open/api/weather/json.shtml?city=$Positi ...
- selector在color和drawable目录下的区别
selector作为drawable资源时,放于drawable目录下,并且item指定android:drawable属性,引用使用@drawable而不是@color selector作为colo ...
- eclipse——Maven创建JavaWeb工程
打包方式改为war 问题:webapp目录下缺少web.xml文件 先勾选掉Dynamic Web Services 点击Applay 再勾选上Dynamic Web Services ,目的是为了产 ...
- [原创]编译CLANG时遇到问题的解决办法
CLANG备忘录: 1.编译时遇到 LINK1123 错误尝试使用其他版本的VS编译,可以有效解决这个问题 2.编译时遇到 Unexpectedfailure executing llvm-build ...
- 《the art of software testing》第六章
更高级别的测试 模块测试的目的是发现程序模块与其接口规格说明之间的不一致 功能测试的目的是为了证明程序未能符合其外部规格说明 系统测试目的是为了证明软件产品与其初始目标不一致 功能测试,作者从三个方面 ...
- 单个控件textbox只支持在英文状态下输入所需的字符串
也就是它的属性: Imemode的属性 设置成off就可以了 ,就不会受到所输入的中文汉字了.
- python核心编程第4章课后题答案(第二版75页)
4-1Python objects All Python objects have three attributes:type,ID,and value. All are readonly with ...