顺序表的合并,最后怎么这样?
#include<stdio.h>#include<stdlib.h>
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef int Status;
typedef int ElemType;
typedef struct{
ElemType *elem;
int length;
int listsize;
}SqList;
int ListLength(SqList L)
{
return L.length;
}
int InitList(SqList &L){
L.elem=(ElemType *)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if(!L.elem)exit(OVERFLOW);
L.length=0;
L.listsize=LIST_INIT_SIZE;
return OK;
}//InitList Sq
Status GetElem(SqList L,int i,ElemType &e)
{
if(i<1||i>L.length)
return ERROR;
e=L.elem[i-1];
return OK;
}
Status ListInsert(SqList &L,int i,ElemType e)
{
ElemType * newbase,*p,*q;
if(i<1||i>L.length+1)
return ERROR;
if(L.length>=L.listsize){
newbase=(ElemType *)realloc(L.elem,(L.listsize+LISTINCREMENT) * sizeof(ElemType));
if(!newbase)
exit(OVERFLOW);
L.elem=newbase;
L.listsize+=LISTINCREMENT;
}
q=&(L.elem[i-1]);
for(p=&(L.elem[L.length-1]);p>=q;--p)
*(p+1)=*p;
*q=e;
L.length++;
return OK;
}
void Print_List(SqList La){
int i;
for(i=0;i<La.length;i++)
printf("%d ",La.elem[i]);
printf("\n");
}// 赋值
void MergeList(SqList La,SqList Lb,SqList &Lc){
int i,j,k;
int La_len,Lb_len;
ElemType ai,bj;
InitList(Lc);
i=j=k=0;
La_len=ListLength(La);
Lb_len=ListLength(Lb);
while((i<=La_len)&&(j<=Lb_len)){
GetElem(La,i,ai);
GetElem(Lb,j,bj);
if(ai<=bj){ListInsert(Lc,++k,ai);++i;}
else{ListInsert(Lc,++k,bj);++j;}
}
while(i<=La_len){
GetElem(La,i++,ai);
ListInsert(Lc,++k,ai);
}
while(j<Lb_len){
GetElem(Lb,j++,bj);
ListInsert(Lc,++k,bj);
}
int main() {
SqList La,Lb,Lc;
int i;
InitList_Sq(La);
InitList_Sq(Lb);
for(i=0;i<10;i++){
scanf("%d",&La.elem[i]);
La.length++; }
for(i=0;i<10;i++){
scanf("%d",&Lb.elem[i]);
Lb.length++;}
MergeList(La,Lb,Lc);
printf("\n顺序表La\n");
print_List(La);
printf("\n顺序表Lb\n");
print_List(Lb);
printf("\n顺序表Lc\n");
print_List(Lc);
}
}
cpp(89) : error C2601: 'main' : local function definitions are illegal