弄了好久了,不知道怎么改
#include<stdio.h>#include<malloc.h>
#include<stdlib.h>
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define ERROR 0
#define OK 1
#define OVERFLOW -2
typedef int ElemType;
typedef struct{
int *elem;
int length;
int listsize;
}SqList;
int InitList_Sq(SqList &L){//空顺序表
L.elme=(ElemType *)malloc(LIST_INIT_SIZE* sizeof(ElemType));
if(!L.elme) exit (OVERFLOW);
L.length=0;
L.listsize=LIST_INIT_SIZE;
return OK;
}
int ListInsert_Sq(SqList &L,int i,ElemType e)
{
int *newbase;
if(i<1 || i>L.length) return (0);
if(L.length>=L.listsize){
newbase=(ElemType *)realloc(L.elem,
(L.listsize+LISTINCREMENT)*sizeof(ElemType));
if(!newbase) exit (OVERFLOW);
L.elem=newbase;
L.listsize+=LISTINCREMENT;
}
// q=&(L.elem[i-1]);
// for(p=&(L.elem[L.lemgth-1]);p>=q;--p)
// *(p+1)=*p;
// *q=e;
L.elem[i-1]=e;
++L.length;
return OK;
}
int GetElem(SqList &L,int i,ElemType e) /*求顺序表中某个数据的元素值 */
{
if(i<1||i>L.length)
return ERROR;
else
e=L.elem[i-1];
return 1;
}
int LocateElem(SqList &L,ElemType e){//比较
int i=0;
while(i<L.length && L.elem[i]!=e) i++;
if(i>=L.length)
{ printf("Illegal Position.");
return 0;
}
else
return i+1;
}
int ListDelete(SqList &L,int i,ElemType e){//删除
int j;
if(i<1 || i>L.length){
printf("Illegal Position.");
return 0;
}
i--;
e=L.elem[i];
for(j=i;j<L.length;j++)
L.elem[j]=L.elem[j+1];
L.length--;
return 1;
}
int DispList(SqList &L){//显示
int i;
if(ListEmpty(L)) return 0;
for(i=0;i<L.length;i++)
printf("%c",L.elem[i]);
printf("\n");
}
main()
{
SqList L;
int m=5,e;
int InitList(L);
printf("请输入数据,以0结束:");
for(int i=0;e!=0;i++)
{
scanf("%d",e);
ListInsert(L,i,e);
}
DispList(L);
for(i=0;i<L.length-1;i++){
GetElem(L,i,e);
if(LocateElem(m,e,equal)) ListDelete(L,--L.length,e);
}
DispList(L);
}