看不懂,也不知哪错了,求大神帮我备注一下意思,谢谢,谢谢
#include <stdio.h>#include <stdlib.h>
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int Status;
typedef int ElemType;
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef struct {
ElemType *elem;
int length;
int listsize;
}SqList;
Status InitList( SqList &L) {
L.elem=(ElemType*)malloc(LIST_INIT_sizeof(EiemType));
if(!L.elem)exit(OVERFLOW);
L.length=0;
L.listsize=LIST_INIT_SIZE;
return OK;
}
void TraverList(SqList L)//输出线性表中的元素
{
int i;
for (i=0;i<L.length;i++)
{
printf("%d\t",L.elem[i]);
}
}
Status ListInsert(SqList &L, int i, ElemType e) {
if(i<1||i>L.length+1) return ERROR;
q=&(L.elem[i-1]);
for(p=&(L.elem[L.length-1]); p>=q; --p)
*(p+1)=*p;
*q=e;
++l.length;
return OK;
}
Status ListDelete(SqList &L, int i, ElemType &e) {
if(i<1||i>L.length+1) 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 LocateElem(SqList L, ElemType e) {
}
void main()
{
SqList L;
int i,choose;
ElemType e;
if (InitList(L)==OVERFLOW) {printf("\nOVERFLOW" );return ;}
TraverList(L);
do{
printf("选择要执行的基本操作:\n1:插入元素;\n2:删除元素;\n3:查找元素;\n");
scanf("%d",&choose);
switch(choose){
case 1:
printf("输入要插入元素的位置和值:\n");
scanf("%d%d",&i,&e);
if (ListInsert(L,i,e)==OK) TraverList(L);
else printf("不能插入!\n");
break;
case 2:
printf("输入要删除元素的位置:\n");
scanf("%d",&i);
if(ListDelete(L,i,e)==OK) TraverList(L);
else printf("删除位置不合法。\n");
break;
case 3:
printf("输入要查找元素的值:\n");
scanf("%d",&e);
if(LocateElem(L,e))
printf("该元素的位置是第 %d位!\n",LocateElem(L,e));
else
printf("该元素不存在!\n");
break;
default:
printf("操作结束!");
return;
}
}while(1);
return;
}