哪位高手帮我看看这个程序错在哪?
我需要把链表程序的将按位置插入和删除改为按给定元素进行查找后插入和删除,我想要的是查找元素后向后插入一个元素,或者按元素查找后删除元素,但是不能实现,哪错了?红色为要改的地方//实验一参考程序如下: //
#include <iostream>
using namespace std;
#define max 100
typedef struct SeqList
{
int elem[max];
int length;
}sqlist;
sqlist L; //定义顺序表L
sqlist CreatList_Sq(sqlist L)
{//创建顺序表
int i;
printf("请输入线性表的长度n:\n");
scanf("%d",&L.length);
printf("\n");
printf("please input %d numbers:\n",L.length);
for (i=1;i<=L.length;i++)
scanf("%d",&L.elem[i]);
printf("\n");
return(L);
}
void display(sqlist L)
{//输出显示函数
int i;
printf("线性表为:\n");
for (i=1;i<=L.length;i++)
printf("%d ",L.elem[i]);
printf("\n");
}
sqlist ListInsert_Sq(sqlist L,int i,int e)
{//在顺序表L的第i个位置插入新元素e
int j;
for(i=0;i<=L.length;i++)
if(L.length==i)
break;
if (i<1||i>L.length)
printf("error");
if (L.length>=max)
printf("overflow");
else
{
for (j=L.length;j>=i;j--)
L.elem[j-1]=L.elem[j];
L.elem[i]=e;
L.length++;
printf("success\n");
};
return(L);
}
sqlist ListDelete_Sq(sqlist l, int i)
{//删除线性表L中第i个元素
int j;
for(i=0;i<=L.length;i++)
if(L.length==i)
break;
if (i<1 ||i>L.length)
printf("I is error\n");
else
{
for (j=i+1;j<=L.length;++j)
L.elem[j-1]=L.elem[j];
L.length--;
printf("success\n");
};
return(L);
}
void main()
{
int num,delnum,f=1;
int p;
int no;
/*clrscr();*/
while(f)
{ printf("请输入0或1、2、3来选择操作:\n0退出\n1顺序表创建\n2顺序表元素插入\n3顺序表元素删除\n");
scanf("%d",&no);
switch(no)
{
case 1: L=CreatList_Sq(L);
display(L);
break;
case 2: printf("please point to the position you want to:\n");
scanf("%d",&p);
printf("Input the inserted number:\n");
scanf("%d",&num);
printf("\n");
L=ListInsert_Sq(L,p,num);
display(L);
break;
case 3: printf("Input the deleted the position of the number:");
scanf("%d",&delnum);
printf("\n");
L=ListDelete_Sq(L,delnum);
display(L);
break;
case 0: break;
}
printf("do you want to continue ?\nno.1:continue\nno.0:exit\n");
scanf("%d",&f);
}
}