请教有关链表的问题
设计一个程序,生成两个按值非递减有序排列的线性表LA和LB,再将LA和LB归并为一个新的线性表LC,且LC中的数据仍按值非递减有序排列,输出线性表LA,LB,LC ?
#include <stdio.h>
struct List
{
int len;
int list[10];
};
void MergeList(List La, List Lb, List &Lc);
void Putout(List La, List Lb, List Lc);
void main()
{
struct List La = {3, {3,4,5}}, Lb = {5, {1,2,3,4,5}}, Lc;
Lc.len = La.len + Lb.len;
MergeList(La, Lb, Lc);
Putout(La, Lb, Lc);
}
void MergeList(List La, List Lb, List &Lc)
{
int i = 0, j = 0, k = 0;
for( ; (i<La.len)&&(j<Lb.len); k++)
if(La.list[i] >= Lb.list[j])
{
Lc.list[k] = Lb.list[j];
j++;
}
else
{
Lc.list[k] = La.list[i];
i++;
}
}
void Putout(List La, List Lb, List Lc)
{
int i;
printf("The elem of list La:\n");
for(i = 0; i<La.len ;i++)
printf("%d ", La.list[i]);
printf("\nThe elem of list Lb:\n");
for(i = 0; i<Lb.len ;i++)
printf("%d ", Lb.list[i]);
printf("\nThe elem of list Lc:\n");
for(i = 0; i<Lc.len ;i++)
printf("%d ", Lc.list[i]);
}