请高手找出这段代码中的错误~~非常感谢!!

来源:百度知道 编辑:UC知道 时间:2024/06/28 06:05:27
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#define MAXSIZE 30;
#define TRUE 1;
#define ERROR -1;
typedef struct
{int data[MAXSIZE];
int length;
}SeqList;
void init_SeqList(SeqList *L)
{ L=(int *)malloc(sizeof(SeqList));
L->length=0;
}
void Input_SeqList(SeqList *L)
{
int i;
printf("请输入顺序表的初步长度:\n");
scanf("%d",&L->length);
printf("请输入整数列(个数不超过30):\n");
for(i=0;i<L->length;i++)
scanf("%d",&L->data[i]);
}
int GetElem_SeqList(SeqList *L,int i)
{ if(i<0||i>=L->length) return ERROR;
else return L->data[i];
}
int Location_SeqList(SeqList *L, int x)
{ int i=0;
while(i<=L->length && L->data[i]!= x)

我给你改了改,语法没有错误了,但是逻辑上不敢保证,同时指出了错误原因;
建议好好看看链表的这里这些基本操作!
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#define MAXSIZE 30
#define TRUE 1
#define ERROR -1

typedef struct
{
int data[MAXSIZE];
int length;
}SeqList;

void init_SeqList(SeqList *L)
{
L=(SeqList *)malloc(sizeof(SeqList)); //这里的类型转换错误;
L->length=0;
}
void Input_SeqList(SeqList *L)
{
int i;
printf("请输入顺序表的初步长度:\n");
scanf("%d",&L->length);
printf("请输入整数列(个数不超过30):\n");
for(i=0;i<L->length;i++)
scanf("%d",&L->data[i]);
}

int GetElem_SeqList(SeqList *L,int i)
{ if(i<0||i>=L->length) return ERROR;
else return L->data[i];
}
int Location_SeqList(SeqList *L, int x)
{ int i=0;
while(i<=L->length && L->data[i]!= x)