Compile problems about ''local function definitions are illegal''
Code:
The details as follows:
#include"stdio.h"
#include"malloc.h"
#define MaxSize 50
typedef int ElemType;
typedef struct
{ElemType elem[MaxSize];
int length;
}SqList;
void CreateList(SqList *&L,ElemType a[],int n)
{int i;
L=(SqList *)malloc(sizeof(SqList));
L->length=0;
for(i=0;i<n;i++)
L->elem[i]=a[i];
L->length=n;}
void DestroyList(SqList *L)
{free(L);}
int ListEmpty(SqList *L)
{return(L->length==0);}
void BubbleSort(SqList *&L)
{int i,j,exchange;ElemType temp;
for(i=0;i<L->length-1;i++)
{exchange=0;
for(j=L->length-1;j>i;j--)
{if(L->elem[j]<L->elem[j-1])
{temp=L->elem[j];L->elem[j]=L->elem[j-1];L->elem[j-1]=temp;exchange=1;}}
if(exchange==0) return;}
int DispList(SqList *L)
{int i;
if(ListEmpty(L)) return 0;
for(i=0;i<L->length;i++)
printf("%d\n",L->elem[i]);
return 1;
}
void ListInsert(SqList *&L,ElemType x)
{int i=0,j;
while(i<L->length&&L->elem[i]<x) i++;
if(L->length!=0&&i!=L->length)
{for(j=L->length-1;j>=i;j--)
L->elem[j+1]=L->elem[j];}
L->elem[i]=x;L->length++;}
void main()
{SqList *L;
ElemType a[8]={3,8,2,6,12,4,9,7};
CreateList(L,a,8);
DispList(L);
BubbleSort(L);
ListInsert(L,5);
DispList(L);
DestroyList(L);
}
compile result with VC:--------------------Configuration: GE - Win32 Debug--------------------
Compiling...
e.cpp
H:\Visual C++ 6.0\新建文件夹\MSDev98\MyProjects\GE\e.cpp(34) : error C2601: 'DispList' : local function definitions are illegal
H:\Visual C++ 6.0\新建文件夹\MSDev98\MyProjects\GE\e.cpp(42) : error C2601: 'ListInsert' : local function definitions are illegal
H:\Visual C++ 6.0\新建文件夹\MSDev98\MyProjects\GE\e.cpp(50) : error C2601: 'main' : local function definitions are illegal
H:\Visual C++ 6.0\新建文件夹\MSDev98\MyProjects\GE\e.cpp(59) : fatal error C1004: unexpected end of file found
Tread awry when execute cl.exe
GE.exe - 1 error(s), 0 warning(s)
I have looked repeatedly but failued to find the problem.
Does here any friend give me a hand?