急啊 哪位帮我改下这个顺序表的程序啊
不知道哪错了 不知道怎样改 #include<studio.h>
#include<stdlib.h>
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int status
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef int ElemType ;
typedef struct {
ElemType *elem;
int length;
int listsize;
} SqList;
Status InitList_Sq(SqList &L)
{
L.elem = (ElemType *) malloc (LIST_INIT_SIZE*sizeof(ElemType));
if (!L.elem) exit (-2);
L.length = 0;
L.listsize = LIST_INIT_SIZE;
return 1;
}
Status CreateList(SqList &L)
{
int i,n;
printf("请输入顺序表长度:");
scanf("%d",n);
for(i=0;i<n;i++);
{
printf("请输入数据原元素数组Elem[i%d]=",i);
scanf("%d",L.elem[i]);
}
return(1);
}
Satus ListLength(SqList L)
{
printf("顺序表的长度为:\n");
scanf("%d",L.length);
return(1);
}
Status GetElem(SqList L,int i,ElemType &e)
{
printf("请输入要查元素的的位置");
scanf("%d",i);
if((i<0)||(i>L.length))
return 0;
else
{
e=L.elem[i-1];
printf("第i%d的位置上的值为%d\n",i,e);
return 1;
}
Status LocateElem(SqList L,ElemType e)
{
int i;
printf("请输入e的值:");
scanf("%d",&e);
for(i=0;i<L.length;i++);
if(L.elem[i-1]!=e)
return 0;
else
printf("e在顺序表中的位置为:%d\n",i-1);
return(1);
}
Status ListInsert_Sq(SqList &L,int i ,ElemType e)
{
printf("请输入要插入的位置");
scanf("%d",i);
printf("请输入插入元素e的值");
scanf("%d",&e);
if(i<1||i>L.length+1) return 0;
if(l.length==L.listsize){
newbase=(Elemtype *)realloc(L.elem,(L.listsize+LISTINCREMENT)*sizeof(ElemType);
if(!newbase) exit(-2);
L.elem=newbase;
L.listsize+=LISTINCREMENT;
}
ElemType *p,*q;
q=&(L.elem[i-1]);
for(p=&(L.elem[L.length-1]);p>=q;--p)
*(p+1)=*p;
*q=e;
++L.length;
printf("插入后的顺序表为:%d\n",L.elem[i])
return 1;
}
Status ListDelet_Sq(SqList &L,int i,ElemType &e)
{
printf("请输入要删除的位置");
scanf("%d",i);
if((i<1)||(i>L.length)) return 0;
ElemType *p,*q;
p=&(L.elem[i-1]);
e= *p;
q=L.elem+L.length-1;
for(++p;p<=q;++p)
*(p-1)=*p;
--L.length;
printf("删除后的顺序表为:%d\n",L.elem[i]);
return 1;
}
Status ShowList(SqList &L,int i)
{
if(L.length=0) exit(0);
else
printf("输出显示:%d\n",L.elem[i]); return(1);
}
void ClearList( SqList &L )
{
L.length=0;
}
Status DestroyList( SqList &L )
{ if (!L.elem) return 0;
free(L.elem);
L.elem=NULL;
L.length=0;
L.listsize=0;
printf("销毁成功");
return 1;
}
void main(){
SqList L;
ElemTYpe e;
int i,n;
InitList_Sq(L);
printf("1.建立顺序表\n");
printf("2.求顺序表长度\n");
printf("3.求顺序表中第i个位置的数据元素数值\n");
printf("4.求数据元素e在顺序表中的位置\n");
printf("5.在第i个位置上插入一个数据元素\n");
printf("6.删除顺序表中第i个位置上的数据元素\n");
pirntf("7.输出显示\n");
pirntf("8.清空顺序表\n");
pirntf("9.销毁顺序表\n");
printf("请输入你的选择\n");
scanf("%d",&i);
while(i!=0){
switch(i)
{
case 1: CreateList(L);break;
case 2: ListLength(L,e,n);break;
case 3: GetElem(L,e,n);break;
case 4: LocateElem(L,e,n);break;
case 5: ListInsert_Sq(L,e,n);break;
case 6:ListDelet_Sq(L,e,n);break;
case 7: ShowList(L,e,n);break;
case 8: ClearList( L,e,n );break;
case 9: DestroyList( L,e,n );break;
case 0: break;
defult:break;
}
}