函数调用
#define list_size 15#define increment 5
#define ok 1
#define overflow -1
#define error -2
#include "stdlib.h"
#include "stdio.h"
typedef struct{ int *elem;
int length;
int listsize;}sqlist;
/**********************************************/
int initlist(sqlist *L)
{ L->elem=(int *)malloc(list_size*sizeof(int));
if(!L->elem) exit(overflow);
L->length=0;
L->listsize=list_size;
return ok; }
/**********************************************/
int listinsert( sqlist *L, int i, int e )
{ int *p,*q,*newbase;
if(i<1||i>L->length+1) return error;
if(L->length>=L->listsize)
{newbase=(int *)realloc(L->elem,(L->listsize+increment)*sizeof(int));
if(!newbase)exit(overflow);
L->listsize+=increment;}
q=&(L->elem[i-1]);
for(p=&(L->elem[L->length-1]);p>=q;--p) *(p+1)=*p; *q=e; ++L->length;
return ok;}
/***********************************************/
int listDelete( sqlist *L, int i )
{
int *p,*q,e;
if(i<1||i>L->length+1) return error;
p=&(L->elem[i-1]);
e=*p;
printf("*********************\n");
printf("%d",e);
q=L->elem+L->length-1;
for(++p;p<=q;++p)
*(p-1)=*p;
--L->length;
return ok;
}
/***********************************************/
int Locateelem(sqlist *L,int e,int(*compare)(int,int))
{
int i,*p;
i=1;
p=L->elem;
while(i<=L->length&&!(*compare)(*p++,e))
++i;
if(i<=L->length) return i;
else return 0;
}
/***********************************************/
void printlist(sqlist *L)
{int i;
printf("\n*********************");
printf("\nThe element of the sqlist are:\n");
for(i=0;i<L->length;i++)
printf("%d ",L->elem[i]);
printf("\n*********************\n");
return;
}
/***********************************************/
main( )
{ int i,j,e;
sqlist L1;
initlist(&L1);
printf("\n Please insert the length of the sqlist:\n");
scanf("%d",&L1.length);
printf("\n Please insert the element of the sqlist:\n");
for(i=0; i<L1.length; i++)
scanf( "%d", &L1.elem[ i ]);
printlist(&L1);
printf("\nPlease insert the value of j ane e :\n");
scanf("%d%d",&j,&e);
listinsert(&L1, j, e);
printlist(&L1);
printf("\nPlease listDelete the value of j ane e :\n");
scanf("%d",&j);
listDelete(&L1, j);
printlist(&L1);
Locateelem(&L1,e,int(*compare)(&L1,e));
}
中的 Locateelem含输调用错误在哪;