这个程序哪里出错了啊???

2024-12-03 15:01:00
推荐回答(1个)
回答1:

#include
#include
/*顺序表的定义:*/
#define ListSize 100
typedef struct
{ int data[ListSize]; /*向量data用于存放表结点*/
int length; /*当前的表长度*/
}SeqList;
void main()
{ void CreateList(SeqList *L,int n);
void PrintList(SeqList *L,int n);
int LocateList(SeqList *L,int x);
void InsertList(SeqList *L,int x,int i);
void DeleteList(SeqList *L,int i);
SeqList L;
int i,x;
int n=10; /*THE LENGTH OF LIST*/
L.length=0;
//clrscr();
CreateList(&L,n); /*CREAT THE LIST*/
PrintList(&L,n); /*PRINT THE LIST*/
printf("INPUT THE RESEARCH ELEMENT\n");
scanf("%d",&x);
i=LocateList(&L,x);
printf("the research position is %d\n",i); /*顺序表查找*/
printf("input the position of insert:\n");
scanf("%d",&i);
printf("input the value of insert\n");
scanf("%d",&x);
InsertList(&L,x,i); /*顺序表插入*/
PrintList(&L,n); /*打印顺序表*/
printf("input the position of delete\n");
scanf("%d",&i);
DeleteList(&L,i); /*顺序表删除*/
PrintList(&L,n);
//getch();/*打印顺序表*/
}

/*顺序表的建立:*/
void CreateList(SeqList *L,int n)
{int i;
printf("please input %d numbers\n",n);
for(i=1;i<=n;i++)
{scanf("%d",&L->data[i]);

}
L->length=n;
}

/*顺序表的打印:*/
void PrintList(SeqList *L,int n)
{int i;
printf("the sqlist is\n");
for(i=1;i<=n;i++)
printf("%d ",L->data[i]);
printf("\n");

}

/*顺序表的查找:*/
int LocateList(SeqList *L,int x)
{int i;
int k;
for(i=1;i<=10;i++)
if((L->data[i])==x)
{k=i;
break;
}
else
k=0;

return k;
}

/*顺序表的插入:*/
void InsertList(SeqList *L,int x,int i)
{int j;
for(j=L->length;j>=i;j--)
L->data[j+1]=L->data[j];
L->data[i]=x;
L->length++;

}

/*顺序表的删除:*/
void DeleteList(SeqList *L,int i)
{ int j;
for(j=i;j<=(L->length)-1;j++)
L->data[j]=L->data[j+1];
}