#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. Assembly.Load动态加载程序集而不占用文件 z

    方式一:占用文件的加载 Assembly assembly = Assembly.Load(path); 用上面的方法可以动态的加载到dll,但是用这种方法加载到的dll一直到程序运行结束都是占用的d ...

  2. win10 下常用shell命令

    shell脚本命令 单行过长如何换行 在一行的结尾加上^即可 , 打印当前目录 %cd%

  3. scala测试框架:scalatest

    api文档:http://tool.oschina.net/apidocs/apidoc?api=scalatest-1.7.2 trait Assertions:http://tool.oschin ...

  4. 关于#include文件包含

    1.对于函数头文件: #include <filename> 一般对于标准库文件以一个.h后缀结尾: 2.对于本地文件: #include "filename.h" 对 ...

  5. Java的身份证号码工具类

    /** * Copyright (C) 2009-2010 Yichuan, Fuchun All rights reserved. * Licensed to the Apache Software ...

  6. 关于hibernate中映射中有many to one等外键关联时的问题

    hibernate中的对象的3种状态的理解及导致报错object references an unsaved transient instance - save the transient insta ...

  7. STL 源码分析 (SGI版本, 侯捷著)

    前言 源码之前,了无秘密 algorithm的重要性 效率的重要性 采用Cygnus C++ 2.91 for windows cygwin-b20.1-full2.exe 下载地址:http://d ...

  8. Windows远程CentOS桌面

    Windows远程CentOS桌面 1.VNC 服务器配置 1) 安装vncserver yum install -y vnc-server 2) 修改配置 vi /etc/sysconfig/vnc ...

  9. perl学习笔记一

    标量数据 标量:数字.字符.可以存储在标量变量中也可以从文件和设备中读取. 数字:所有数字内部格式相同——双精度浮点数. 浮点数直接量:程序员在程序中直接键入的数字. 整数直接量:6129804028 ...

  10. Android学习(十三) BroadcastReceiver组件(广播)

    一.Broadcast(广播) 是一种广泛应用在应用程序之间传输信息的机制. 二.Broadcast(广播接收器) 是对发送出来的广播进行过滤接收并响应的一类组件,它就是用来接收来自系统和应用中的广播 ...