#include "stdio.h"
#include "stdlib.h"
#include "function.h"
void main()
{

Sqlist L,L1,L2;

InitList(&L);
InitList(&L1);
InitList(&L2);

ListInsert(&L, 1, 3);//f(n)
ListInsert(&L, 2, 5);
ListInsert(&L, 1, 8);
ListInsert(&L, 1, 11);

ListInsert(&L1,1,2);
ListInsert(&L1,2,6);
ListInsert(&L1,3,8);
ListInsert(&L1,3,9);
ListInsert(&L1,3,11);
ListInsert(&L1,3,15);
ListInsert(&L1,3,20);
//对顺序表L进行排序
int tmp = 0;
for (int i = 0; i <L.length-1; i++)
{
for (int j = i + 1; j < L.length; j++) {
if (L.elem[i] > L.elem[j]) {
tmp = L.elem[i];
L.elem[i] = L.elem[j];
L.elem[j] = tmp;
}

}
}

tmp = 0;

for (int i = 0; i <L1.length - 1; i++)
{
for (int j = i + 1; j < L1.length; j++) {
if (L1.elem[i] > L1.elem[j]) {
tmp = L1.elem[i];
L1.elem[i] = L1.elem[j];
L1.elem[j] = tmp;
}

}
}
int k = 0;
int j = 0;
while ((k<L.length)&&(j<L1.length))
{
if (L.elem[k] <= L1.elem[j])
{
ListInsert(&L2, L2.length + 1, L.elem[k]);
k++;
}
else
{
ListInsert(&L2, L2.length + 1, L1.elem[j]);
j++;

}
}

if (k >= L.length) {
for (int i = j; i < L1.length; i++)
{
ListInsert(&L2, L2.length + 1, L1.elem[i]);

}
}
if (j>=L1.length) {
for (int i = k; i < L.length; i++)
{
ListInsert(&L2, L2.length + 1, L.elem[i]);

}
}

//输出顺序链表中的所有值
for (int i = 0; i < L2.length; i++)
{
printf("元素的第%d个值为%d\n", i + 1, L2.elem[i]);

}

}

该算法的时间复杂度为O(f(L1)+f(L))

将非递减有序排列(L L1)归并为一个新的线性表L2 线性表L2中的元素仍按值非递减的更多相关文章

  1. 谷歌笔试题--给定一个集合A=[0,1,3,8](该集合中的元素都是在0,9之间的数字,但未必全部包含), 指定任意一个正整数K,请用A中的元素组成一个大于K的最小正整数。

    谷歌笔试题--给定一个集合A=[0,1,3,8](该集合中的元素都是在0,9之间的数字,但未必全部包含), 指定任意一个正整数K,请用A中的元素组成一个大于K的最小正整数. Google2009华南地 ...

  2. /编写一个函数,要求从给定的向量A中删除元素值在x到y之间的所有元素(向量要求各个元素之间不能有间断), 函数原型为int del(int A ,int n , int x , int y),其中n为输入向量的维数,返回值为删除元素后的维数

    /** * @author:(LiberHome) * @date:Created in 2019/2/28 19:39 * @description: * @version:$ */ /* 编写一个 ...

  3. 《笔记篇》非JS方法跳转到一个新页面,主要防止客户端禁止浏览器JS以后的跳转异常

    用非JS方法打开一个新页面,主要防止客户端禁止浏览器JS以后的跳转失效 <meta http-equiv="refresh" content="0; url=htt ...

  4. 缺少新的栈标识:报出异常FLAG_ACTIVITY_NEW_TASK flag-是由于activity关闭之后开启一个新的acitivity时没有标识在栈中,所以需要给一个栈标识

    异常(栈里必须有activity的flag标识): 05-02 08:43:36.173: E/AndroidRuntime(3328): android.util.AndroidRuntimeExc ...

  5. map() 方法创建一个新数组,其结果是该数组中的每个元素都调用一个提供的函数后返回的结果。

    var numbers = [1, 4, 9]; var roots = numbers.map(Math.sqrt); // roots的值为[1, 2, 3], numbers的值仍为[1, 4, ...

  6. 获得一个list中某元素的索引值

    list = [1,2,3,3,2,1] list.index(1) # 只能获得首个1的索引值 如果要获得所有该元素的索引值 import numpy as np arr = np.array(li ...

  7. 将WinForm程序(含多个非托管Dll)合并成一个exe的方法

    原文:将WinForm程序(含多个非托管Dll)合并成一个exe的方法 开发程序的时候经常会引用一些第三方的DLL,然后编译生成的exe文件就不能脱离这些DLL独立运行了. ILMerge能把托管dl ...

  8. 给定一个数组,求如果排序之后,相邻两数的最大差值,要求时间复杂度为O(N),且要求不能用非基于比较的排序

    题目: 给定一个数组,求如果排序之后,相邻两数的最大差值,要求时间复杂度为O(N),且要求不能用非基于比较的排序 public static int maxGap(int nums[]) { if ( ...

  9. C语言合并两个集合(L,L1) 将L1中不在L中的元素插入到L线性表中

    void main(){ Sqlist L,L1; InitList(&L); InitList(&L1); ListInsert(&L, 1, 2); ListInsert( ...

随机推荐

  1. elasticsearch升级步骤

    ES从1.2.1升级到1.4.0 升级步骤,基本上是按照官网的叙述来完成的,链接是:http://www.elasticsearch.org/guide/en/elasticsearch/refere ...

  2. CentOS7.4 x64环境Percona-Server-5.6安装

    CentOS7.4 x64环境Percona-Server-5.6安装 下载MySQL $ cd /usr/local/src/ $ wget https://www.percona.com/down ...

  3. 2017.7.1 ftp文件服务器安装与配置(已验证可使用)

    下载地址:http://learning.happymmall.com/ 1.点击exe文件 2.启动ftpserver 点击exe后,就出现如下画面:输入账户密码和勾选权限等. 并配置好对应的文件夹 ...

  4. Some perl tips

    下面是日常工作中一些代码片段的总结,部分注释是后加的,采用了//这种形式,请勿套用. 1.取得用户输入print("Please input the date range:");$ ...

  5. react-native 路由 react-native-router-flux

    引言 react-native-router-flux 是一个基于 react-navigation 路由框架,进一步简化了页面跳转的步骤,并且一直随着 react-navigation升级更新版本. ...

  6. react-native 项目实战 -- 新闻客户端(2) -- 完善TabBar

    1.创建 drawable-xxhdpi 文件夹,保存 TabBar 的 icon图标 android  --  app  --  src  --  main  --  res  --  drawab ...

  7. 【VAB】获取库文件地址

    如何获取Excle库文件地址呢?具体代码如下: Public Sub 获取Excel库文件夹的路径() MsgBox "库文件夹的路径是: " & Application. ...

  8. 用SwiftGen管理UIImage等的String-based接口

    代码地址如下:http://www.demodashi.com/demo/12149.html 问题现状 平时我们使用UIImage,UIFont,UIColor会遇到很多String-based的接 ...

  9. 基于Android Classic Bluetooth的蓝牙聊天软件

    代码地址如下:http://www.demodashi.com/demo/12133.html BluetoothChat 基于Android Classic Bluetooth的蓝牙聊天软件,目前仅 ...

  10. Caused by: java.lang.ClassNotFoundException: Didn't find class "** *** ** **" on path: DexPathList[[zip file "/data/app/*** *** ***-2/base.apk"],nativeLibraryDirectories

    Caused by: java.lang.ClassNotFoundException: Didn't find class "** *** ** **" on path: Dex ...