线性表插入,删除,求指教
#include <stdio.h>#include <stdlib.h>
#define list 10
#define listadd 10
typedef int Status;
typedef int Elemtype;
typedef struct
{
Elemtype * elem;
int length;
int listsize;
}Sqlist;
Status Intlist(Sqlist & l)
{
l.elem=(Elemtype *)malloc (list * sizeof (Elemtype));
if (! l.elem)
exit (-1);
l.length = 0;
l.listsize = 10;
printf("请输入10个数字:\n");
for (int i=0;i<10;i++)
{
scanf("%d",&l.elem[i]);
}
for (int j=0;j<10;j++)
{
printf("%d ",l.elem[j]);
}
printf("\n");
return 1;
}
Status listinsert(Sqlist & l,int i,Elemtype e )
{
Elemtype *q,*newbase,*p;
if(i<1||i>l.length+1)
return -1;
if(l.length>=l.listsize)
{
newbase = (Elemtype * )realloc (l.elem,(list+listadd)*sizeof (Elemtype));
if(!newbase)
return -1;
l.elem=newbase;
l.listsize+=10;
}
q=&(l.elem[i-1]);
for (p=&(l.elem[l.length - 1]);p>=q;--p)
*(p+1)=*p;
*q=e;
++l.length ;
return 1;
}
Status listdelete (Sqlist &l,int i, Elemtype &e)
{
Elemtype * q,*p;
if (i<1||i>l.length )
return -1;
p=&l.elem[i-1];
e=*p;
printf("%d",e);
printf("\n");
q=l.elem+l.length-1;
for (++p;p<=q;++p)
*(p-1)=*p;
--l.length ;
for (int n=0;i<l.length;n++)
printf("%d\t",l.elem[n]);
printf("\n");
return 1;
}
void main ()
{ int k=3,e=0;
Sqlist l;
Intlist(l);
listinsert(l,k,e);
listdelete(l,k,e);
}
我想要输出删除和插入后的数据,求指教!