用C语言把两个单链表合成一个新链表,代码写到一半写不下去,求帮忙?
#include "stdio.h"
#include "stdlib.h"
#define LIST_INIT_SIZE 100
#define OVERFLOW -2
#define ERROR 0
#define OK 1
#define LISTINCREMENT 10
typedef int ElemType;
typedef int Status;
typedef struct sqlist
{ ElemType*elem;
int listlength;
int listsize;
}SqList;
Status InitList_Sq(SqList*L)
{ L->elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if(!L->elem) exit(OVERFLOW);
L->listlength=0;
L->listsize=LIST_INIT_SIZE;
return OK;
}
int Listlength (SqList*L)
{ return L->listlength;
};
int GetElem(SqList*L,int i,ElemType e)
{
if(0elem[i-1];
else
return ERROR;
}
Status ListInsert_Sq(SqList*L,int i ,ElemType e)
{
ElemType *newbase,*p,*q;
if(iL->listlength+1) return ERROR;
if(L->listlength>=L->listsize)
{ newbase = (ElemType *)realloc(L->elem,(L->listsize+LISTINCREMENT) * sizeof (ElemType));
if(!newbase) exit(OVERFLOW);
L->elem=newbase;
L->listsize=L->listsize+LISTINCREMENT;
}
q=&(L->elem[i-1]);
for(p=&(L->elem[L->listlength-1]);p>=q;--p)
*(p+1)=*p;
L->elem[i-1]=e;
++L->listlength;
return OK;
}
void MergeList(SqList La,SqList Lb,SqList*Lc)
{
ElemType i,j,k,La_len,Lb_len,ai,bj;
InitList(Lc);
i=j=1;k=0;
La_len=ListLength(La);Lb_len=ListLength(Lb);
while((i |
免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。
版权声明:作者保留权利,不代表天盟立场。
|
|
|
|