求大师帮忙改一下,一直找不到错误
#include <stdio.h>#include <malloc.h>
#include <stdlib.h>
#define List_size 100
#define List_inc 10
#define N 10
typedef struct
{
int *elem;
int length;
int listsize;
}SqList;
int InitList_Sq(SqList &L)
{
L.elem=(int*)malloc(List_size*sizeof(int));
if(! L.elem) exit(0);
L.length=0;
L.listsize=List_size;
return 1;
} //创建一张线性表;
int ListInsert_Sq(SqList &L,int i, int e)
{
int *q,*p,*newbase;
if(i<0||i>L.length) return 0;
if(L.length>=L.listsize)
{
newbase=(int *)realloc(L.elem,
(L.listsize+List_inc)*sizeof(int));
if(!newbase) exit(0);
L.elem=newbase;
L.listsize+=List_inc;//线性表空间不够扩展新空间;
}
q=&(L.elem[i]);
for(p=&(L.elem[L.length-1]);p>=q; --p)
*(p+1)=*p; //先将位置i及其后的元素后移
*q=e; //再将元素e保存在位置i
++L.length; //长度加1;
return 1;
} //在线性表i位置插入一新元素;
int ListDelete_Sq(SqList &L,int i)
{
int *p,*q;
if((i<0)||(i>L.length)) return 0;
p=&(L.elem[i]);
q=L.elem+L.length-1;
for(++p;p<=q;++p) //将位置i后的元素前移,覆盖
*(p-1)=*p; //前一元素
*p=0; //最后一位清零
--L.length; // 长度减1;
return 1;
} //与插入相反,删除位置i的元素;
void DeleteTheSame_Sq(SqList &L)
{
int i,j;
for(i=0;i<L.length;++i) //查找与元素elem[i]相同的
{ //所有元素,进行删除;
j=i+1;
while(j<L.length)
{
while((j<L.length)&&(L.elem[j]!=L.elem[i]))
++j;
if(j<L.length)
{
if(ListDelete_Sq(L,j)) //查到一个elem[j]就 删除一个;
;
else
{
printf("ERROR!\n");
exit(0);
} //删除线性表重复元素,无论线性表的元素
} //是否有序,即将程序1,2合并实现
}
}
}
void Putout_Sq(SqList L)
{
int i;
for(i=0;i<L.length;++i)
printf("%2d",L.elem[i]);
printf("\n");
} //输出线性表;
int main()
{
SqList L;
int i,e,flag;
if(InitList_Sq(L))
{
i=1; flag=1;
while(flag && i<=N)
{
printf("Pleast enter No.%d:",i);
scanf("%d",&e);
flag=ListInsert_Sq(L,i-1,e);
i++;
}
} //输入N个元素;
Putout_Sq(L);
DeleteTheSame_Sq(L); //删除线性表中重复元素;
Putout_Sq(L);
return 0;
}