//使用顺序存储Or链式存储来实现线性表一些操作:线性表的合并、有序表的合并
//线性表的合并,算法概述:将两个线性表合并,去除重复的数据
#include <stdio.h>
typedef struct Linkline{
int length;
int arr[];
}Linkline;
int main(){
//先使用顺序存储来实现,定义两个线性表,La:0 2 5 8,Lb: 3 4 9;
Linkline La = { 4, { 1, 2, 4, 8 } };
Linkline Lb = { 3, { 7, 2, 8} };
Linkline Lc = { 7, { 0, 0, 0, 0, 0, 0, 0 } };
int i = 0;
for (i; i < Lb.length; i++){
int j = 0;
for (j; j < La.length; j++){
if (La.arr[j] == Lb.arr[i]){
//如果相同,则删掉一个数组元素
int n = 0;
n = i;
for ( n; n < Lb.length; n++){
Lb.arr[n] = Lb.arr[n + 1];
}
Lc.length= Lc.length - 1;
//删除掉一个数组元素,下一个元素上来,则需要重新遍历
j = 0;
}
}
}
for (int m = 0; m < La.length; m++){
printf("%d\n", La.arr[m]);
}
for (int z = 0; z < Lc.length - La.length; z++){
printf("%d\n", Lb.arr[z]);
}
}