eg:顺序表A:1 3 5 7
顺序表B:2 4 6 8
合并后的表C:8 7 6 5 4 3 2 1
**思路:**从后往前遍历顺序表A和B,如果当前A表的数大于等于B表的数,则将A表的数存入C,A的元素下标往前移一位,否则,将B表的数存入C表,B的元素下标往前移一位B;最后再把其中一个未遍历完的表存入C表。
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#define LIST_INIT_SIZE 100 // 线性表存储空间的初始分配量
#define LISTINCREMENT 10 // 线性表存储空间的初分配增量
#define OVERFLOW -1
#define OK 1
typedef int ElemType;
typedef int Status;
typedef struct {
ElemType *elem; // 存储空间基址
int length; // 当前长度
int listsize; // 当前分配的存储容量
}SqList;
//初始化线性表
Status InitList_Sq(SqList *L) {
L -> elem = (ElemType *) malloc (LIST_INIT_SIZE * sizeof(ElemType));
if (!L -> elem) exit(OVERFLOW); // 存储分配失败
L -> length = 0; // 空表长度为0
L -> listsize = LIST_INIT_SIZE; // 初始存储容量
return OK;
}
//创建有序表并赋值
void Create_Sq(SqList *L) {
int n;
printf("\n输入该有序表元素的个数:");
scanf("%d&