主题:高手帮忙找错误
#include<stdio.h>
#include <stdlib.h>
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int Status;
typedef int ElemType;
typedef struct SqList
{ElemType * elem;
int length;
int listsize;
}SqList;
status InitList(SqList &L);
status GetElem(SqList &L,int i,ElemType &a);
status ListInsert(SqList &L,int i,ElemType e);
status MergeList(SqList La,SqList Lb,SqList &Lc);
void Input_List(SqList &L);
void put_List(SqList &L);
void main()
{SqList La,Lb,Lc;
InitList(La);
InitList(Lb);
Input_List(La);
Input_List(Lb);
MergeList(La,Lb,Lc);
put_List(Lc);
}
status 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;
}
status GetElem(SqList &L,int i,ElemType &a)
{if(i<0||i>=L.length) return ERROR;
a=L.elem[i-1];
return a;
}
status ListInsert(SqList &L,int i,ElemType e)
{ElemType newbase;
if(i<0||i>L.length) return ERROR;
if(L.length>=L.listsize)
{newbase=(ElemType*)realloc(L.elem,LIST_INIT_SIZE+LISTINCREMENT)*sizeof(ElemType);
if(!newbase) exit(OVERFLOW);
L.elem=newbase;
L.listsize+=LISTINCREMENT;
}
L.elem[i-1]=e;
++length;
return OK;
}
void MergeList(SqList La,SqList Lb,SqList &Lc)
{IintList(Lc);
int i,j,k;
i=j=k=0;
while((i<La.length)&&j<La.length))
{GetElem(La,i,a);GetElem(Lb,j,b);
if(a<=b){ListInsert(Lc,++k,a);++i;}
esle {ListInsert(Lc,++k,b);++j;}
}
while(i<La.length){GetElem(La,i++,a);ListInsert(Lc,++k,a);}
while(j<Lb.length){GetElem(Lb,j++,b);ListInsert(Lc,++k,b);}
}
void Input_List(SqList &L)
{int n;
printf("please input the length of L:");
scanf("%d",&n);
printf("please input L:");
for(i=0;i<n;i++)
scanf("%d",&L.elem[i]);
}
void put_List(SqList &L)
{for(i=0;i<L.length;i++)
printf("%d",L.elem[i]);
}
运行出现C:\Program Files\Microsoft Visual Studio\MyProjects\2\1.cpp(17) : error C2146: syntax error : missing ';' before identifier 'InitList'
C:\Program Files\Microsoft Visual Studio\MyProjects\2\1.cpp(17) : error C2501: 'status' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\2\1.cpp(17) : fatal error C1004: unexpected end of file found
请高手帮忙修改!!!
#include <stdlib.h>
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int Status;
typedef int ElemType;
typedef struct SqList
{ElemType * elem;
int length;
int listsize;
}SqList;
status InitList(SqList &L);
status GetElem(SqList &L,int i,ElemType &a);
status ListInsert(SqList &L,int i,ElemType e);
status MergeList(SqList La,SqList Lb,SqList &Lc);
void Input_List(SqList &L);
void put_List(SqList &L);
void main()
{SqList La,Lb,Lc;
InitList(La);
InitList(Lb);
Input_List(La);
Input_List(Lb);
MergeList(La,Lb,Lc);
put_List(Lc);
}
status 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;
}
status GetElem(SqList &L,int i,ElemType &a)
{if(i<0||i>=L.length) return ERROR;
a=L.elem[i-1];
return a;
}
status ListInsert(SqList &L,int i,ElemType e)
{ElemType newbase;
if(i<0||i>L.length) return ERROR;
if(L.length>=L.listsize)
{newbase=(ElemType*)realloc(L.elem,LIST_INIT_SIZE+LISTINCREMENT)*sizeof(ElemType);
if(!newbase) exit(OVERFLOW);
L.elem=newbase;
L.listsize+=LISTINCREMENT;
}
L.elem[i-1]=e;
++length;
return OK;
}
void MergeList(SqList La,SqList Lb,SqList &Lc)
{IintList(Lc);
int i,j,k;
i=j=k=0;
while((i<La.length)&&j<La.length))
{GetElem(La,i,a);GetElem(Lb,j,b);
if(a<=b){ListInsert(Lc,++k,a);++i;}
esle {ListInsert(Lc,++k,b);++j;}
}
while(i<La.length){GetElem(La,i++,a);ListInsert(Lc,++k,a);}
while(j<Lb.length){GetElem(Lb,j++,b);ListInsert(Lc,++k,b);}
}
void Input_List(SqList &L)
{int n;
printf("please input the length of L:");
scanf("%d",&n);
printf("please input L:");
for(i=0;i<n;i++)
scanf("%d",&L.elem[i]);
}
void put_List(SqList &L)
{for(i=0;i<L.length;i++)
printf("%d",L.elem[i]);
}
运行出现C:\Program Files\Microsoft Visual Studio\MyProjects\2\1.cpp(17) : error C2146: syntax error : missing ';' before identifier 'InitList'
C:\Program Files\Microsoft Visual Studio\MyProjects\2\1.cpp(17) : error C2501: 'status' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\2\1.cpp(17) : fatal error C1004: unexpected end of file found
请高手帮忙修改!!!