删除线性表中所有小于小于x的元素,我不知道我的代码哪里错,帮忙改改好吗?
#include<stdio.h>#include<malloc.h>
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define ERROR 0
#define OK 1
#define ElemType int
typedef struct
{
ElemType *elem;
int length;
int listsize;
}Sqlist;
int InitList_Sq(Sqlist &L) //构造线性表
{ int n,i;
scanf("%d",&n);
L.elem=(ElemType*)malloc(n*sizeof(ElemType));
if(!L.elem)
return ERROR;
L.length=0;
L.listsize=n;
for(i=0;i<n;i++)
{scanf("%d",&L.elem[i]);
L.length++;}
return OK;
}
int ListDelete_Sq1(Sqlist &L,int i,ElemType &e) //删除第I个元素,用E返回其值
{
ElemType *q,*p;
if(i<1||(i>L.length))
return ERROR;
p=&(L.elem[i-1]);
e=*p;
q=L.elem+L.length+1;
for(++p;p<=q;++p)
*(p-1)=*p;
--L.length;
return OK;
}
int ListDelete_Sq2(Sqlist &L,ElemType &e)
{ int i;
for(i=0;i<L.length;i++)
{
if(L.elem[i]<e)
{
ListDelete_Sq1(L,i,e);
L.length--;
}
}
return OK;
}
int ListLoad_Sq(Sqlist &L)
{
int i;
for(i=0;i<L.length;i++)
printf("%d ",L.elem[i]);
return OK;
}
int main(void)
{
Sqlist L;
int x;
InitList_Sq(L);
ListLoad_Sq(L);
scanf("%d",&x);
ListDelete_Sq2(L,x);
ListLoad_Sq(L);
return OK;
}