将La和Lb合并成Lc合并问题#include "stdio.h"typedef struct{int elem;}List;void MergeList(List La ,List Lb ,List &Lc ){int i,j,k;InitList(Lc);i=j=1;k=0;La_len = ListLength(La);Lb_len = ListLength(Lb);while ((i

问题描述:

将La和Lb合并成Lc合并问题
#include "stdio.h"
typedef struct{
int elem;
}List;
void MergeList(List La ,List Lb ,List &Lc ){
int i,j,k;
InitList(Lc);
i=j=1;k=0;
La_len = ListLength(La);Lb_len = ListLength(Lb);
while ((i

#include
typedef struct
{
\x09int *elem;
\x09int length;
\x09int listsize;
}SqList;
void InitList(SqList *L)//初始化函数
{
\x09L->elem=(int*)malloc(100*sizeof(int));
\x09if(!(L->elem))
\x09\x09exit(0);
\x09L->length=0;
\x09L->listsize=100;
}
int ListInsert(SqList *L,int i,int e)
{
\x09int newbase,*q,*p;
\x09if(iL->length+1)
\x09\x09return 0;
\x09if(L->length>=L->listsize)
\x09{
\x09\x09newbase=(int*)realloc(L->elem,(L->listsize+10)*sizeof(int));
\x09\x09if(!newbase)
\x09\x09\x09exit(0);
\x09\x09L->elem=newbase;
\x09\x09L->listsize+=10;
\x09}
\x09q=&(L->elem[i-1]);
\x09for(p=&(L->elem[L->length-1]);p>=q;--p)
\x09{
\x09\x09*(p+1)=*p;
\x09}
\x09*q=e;
\x09++L->length;
}
int GetElem(SqList L,int i,int *e)
{
\x09if(iL.length)
\x09\x09return 0;
\x09else
\x09{
\x09\x09*e=L.elem[i-1];
\x09\x09return 1;
\x09}
}
void MergeList(SqList La,SqList Lb,SqList *Lc)
{
\x09int i=1,j=1,k=0;
\x09int ai,bj;
\x09int La_len=La.length,Lb_len=Lb.length;
\x09while((i