数据结构实验之链表四:有序链表的归并(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 在一个给定的无重复元素的递增序列里,查找与给 ...
随机推荐
- Go语言注意事项
必须恰当导入需要的包,缺少了必要的包或者导入了不需要的包,程序都无法编译通过.这项严格要求避免了程序开发过程中引入未使用的包(译注:Go语言编译过程没有警告信息,争议特性之一 import 声明必须跟 ...
- shell习题第14题:
[题目要求] 需求,根据web服务器的访问日志,把一些请求高的ip给拒绝掉,并且每隔半小时把不再发起请求或者请求量很小的ip给解封 假设: 1. 一分钟内请求量高于100次的ip视为不正常的请求 2. ...
- MySQL create table语法中的key与index的区别
在create table的语句中,key和index混淆在一起,官方手册中的解释是这样: KEY is normally a synonym for INDEX. The key attribute ...
- sql server 数据库中明明有值但是查询怎么都查不到值
产生原因是因为编码问题 数据库是英文版 但是数据库中数据又是中文的 所以查询中文时需要加上N select * from customer where Username=N'张三'
- MySQL设置自增字段
1.MySQL每张表只能有1个自增字段,这个自增字段即可作为主键,也可用作非主键使用,但是请注意将自增字段当做非主键使用时必须为其添加唯一索引,否则系统将会报错 )将自动增长字段设置为主键 CREAT ...
- OPENGL 显示BMP图片+旋转
VS2010/Windows 7/ 1. 需包含头文件 stdio.h, glaux.h, glut.h.需要对应的lib,并添加包含路径 2. 窗口显示用glut库的函数 3. bmp图片从本地读取 ...
- 关于EF数据迁移的个人总结 简单有效
有用的拿走,没用的嘴下留情!
- Django rest-framework框架-认证组件的简单实例
第一版 : 自己写函数实现用户认证 #models from django.db import models #用户表 class UserInfo(models.Model): user_type_ ...
- 【php设计模式】装饰器模式
装饰器模式,顾名思义,就是对已经存在的某些类进行装饰,以此来扩展一些功能.其结构图如下: Component为统一接口,也是装饰类和被装饰类的基本类型. ConcreteComponent为具体实现类 ...
- 如何确定asp.net请求生命周期的当前处理事件
1 首先在全局应用程序里面添加如下代码 using System; using System.Collections.Generic; using System.Linq; using System. ...