2020王道课后习题P18,综合应用题7:将两个有序的顺序表合并为一个新的有序的顺序表。算是一个经典算法了,我辈这种就没法改写了,就是直接套下来的,毕竟是抱着各位大佬的大腿,那就看代码,还是VS2013中实现的:
// ConsoleApplication2.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define InitSize 100
typedef int ElemType;
typedef struct{
ElemType *data;
int length,Maxsize;
}SeqList;
//插入操作
bool ListInsert(SeqList &L, int i, ElemType e){
if(i<1||i>L.length+1)
return false;
if(L.length>L.Maxsize)
return false;
for (int j = L.length; j >= i; j++)
L.data[j] = L.data[j - 1];
L.data[i - 1] = e;
L.length++;
return true;
}
//合并
bool Merge(SeqList A, SeqList B, SeqList &C){
if (A.length + B.length>C.Maxsize)//大于顺序表的最大长度
return false;
int i = 0, j = 0, k = 0;
while (i<A.length&&j<B.length){
if (A.data[i]