您当前位置:主页 > 资讯 > 详情

哪位大侠能解释一下这段C代码哪里出错了,还有sqSearch函数里的参数sqList和*L之间怎么没空格?

2024-07-29 17:47 |admin |来源:未知

#define maxlen 1000

#includestdio.h

typedef int elemtype;

typedef struct

{

elemtype elem[maxlen];

int len;

} sqList;

sqList *L; // 没用上

int sqSearch(sqList*L,elemtype x)

{//在顺序表L中查找数据元素x在表中第一次出现的位置

int j;

for(j=0;j<L->len;j++)

if(L->elem[j]==x)

return(j+1);

return(0);

}

int sqInsert(SqList *L,elemtype x,int i) // 注意大小写,SqList 应改为sqList

{

int j,n;

n=L->len;

if(i<1 || i>n+1) // 应该是i>n才对

{

printf(Error);

return (0);

}

if(n>=maxlen)

{

printf(Overflow);

return(0);

}

for(j=n;j>=i;j--)

L->elem[j]=L->elem[j-1];

L->elem[i-1]=x;

l->len++;

return(1);

}

其他并没有错误