还有大家看看这个有错误怎么改;
发现在红色的部分L->length的初始化是一个随机的数,在vc下不能运行,在gcc下是可以,但是结果
#include <stdio.h>
#include <malloc.h>
#define MaxSize 50
typedef char ElemType;
typedef struct
{ElemType elem[MaxSize];
int length;
}SqList;
void main()
{SqList *L;
ElemType e;
void InitList(SqList *L);
int ListtEmpty(SqList *L);
int ListLength(SqList *L);
void DispList(SqList *L);
int GetElem(SqList *L,int i,ElemType e);
int ListInsert(SqList *L,int i,ElemType e);
printf("Init the List\n");
InitList(L);
printf("input a,b,c,d,e\n");
ListInsert(L,1,'a');
ListInsert(L,2,'b');
ListInsert(L,3,'c');
ListInsert(L,4,'d');
ListInsert(L,5,'e');
printf("output L:\n");
DispList(L);
printf("the L length=%d\n",ListLength(L)) ;
}
void InitList(SqList *L)
{L=(SqList *)malloc(sizeof(SqList));
L->length=0;
}
int ListEmpty(SqList *L)
{return(L->length==0);
}
int ListLength(SqList *L)
{return (L->length);
}
void DispList(SqList *L)
{int i;
if (ListEmpty(L)) return;
for(i=0;i<L->length;i++)
printf("%c",L->elem[i]);
printf("\n");
}
int ListInsert(SqList *L,int i,ElemType e)
{int j;
if(i<1||i>L->length)
return 0;
i--;
for(j=L->length;j>i;j--)
L->elem[j]=L->elem[j-1];
L->elem[i]=e;
L->length++;
return 1;
}