C语言新手关于数据结构的问题

写了下面的程序,为了实现用顺序存储结构实现线性表,要求该线性表具有以下功能:
根据输入的数据构建线性表;
打印线性表的长度;
数据元素的插入和删除;
定位指定的数据元素;
程序如下
#include<stdio.h>
#include<stdlib.h>
#define list_init_size 100
#define listincrement 10
typedef int elemtype;
typedef int status;
typedef struct
{
int *elem;
int length;
int listsize;
}sqlist;
void initlist_sq(sqlist *l)
{
int x,p=0;
l->elem=(int*)malloc(list_init_size*sizeof(int));
l->length=0;
l->listsize=list_init_size;
printf("请为初始化顺序表输入整型元素:\n");
scanf("%d",&x);
while(x!=-1)
{
l->elem[p++]=x;
l->length++;
scanf("%d",&x);
}

}

int listinsert_sq(sqlist &l,int i, elemtype e)
{
int * q , *p ,* newbase;
if(i<1||i>l.length+1) return 0;
if(l.length>=l.listsize)
{
newbase=(elemtype *)realloc(l.elem,(l.listsize+listincrement) * sizeof(elemtype));
l.elem=newbase;
l.listsize+=listincrement;
}
q=&(l.elem[i-1]);
for(p=&(l.elem[l.length-1]);p>=q;--p)
*(p+1)= *p;
*q=e;
++l.length;
return 1;
}
int listdelete_sq(sqlist &l,int i,elemtype e)
{
int * q , *p;
if((i<1)||(i>l.length)) return 0;
p=&(l.elem[i-1]);
e=*p;
q=l.elem+l.length-1;
for(++p;p<=q;++p) *(p-1)=*p;
--l.length;
return 1;
}
int locateelem_sq(sqlist l,elemtype e,status(*compare)(elemtype,elemtype))
{
int i=1,*p;
p=l.elem;
while(i<=l.length&&!(*compare)(*p++,e)) ++i;
if(i<=l.length) return i;
else return 0;
}

void Union(sqlist &la,sqlist lb)
{
elemtype e;
int la_len,lb_len;
int i;
la_len=listlength(la);
lb_len=listlength(lb);
for(i=1;i<=lb_len;i++)
{
getelem(lb,i,e);
if(!locateelem_sq(la,e,equal))
listinsert_sq(la,++la_len,e);
}
}
void print(elemtype &c)
{
printf("%d ",c);
}

void main()
{
int i;
sqlist l;
initlist_sq(&l);
printf("the length will be %d\n",l.length);
listinsert_sq(l, 2, 15);
for(i=0;i<l.length;i++)
printf("the left data %d\n",l.elem[i]);
listdelete_sq(l,2,15);
for(i=0;i<l.length;i++)
printf("the left data %d\n",l.elem[i]);
locateelem_sq(l,23,(15,15));
printf("the position of the certain data is %d",i);
Union(l,l);

}
错误如下error C2065: 'listlength' : undeclared identifier
D:\学习资料\数据结构\我的代码\adsdf.cpp(76) : error C2065: 'getelem' : undeclared identifier
D:\学习资料\数据结构\我的代码\adsdf.cpp(77) : error C2065: 'equal' : undeclared identifier
D:\学习资料\数据结构\我的代码\adsdf.cpp(98) : error C2664: 'locateelem_sq' : cannot convert parameter 3 from 'const int' to 'int (__cdecl *)(int,int)'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
请教如何修改,回答好了再加分,谢谢大家了!!

倒数第5行locateelem_sq(l,23,(15,15));改成locateelem_sq(l,23,equal);

把下面三个访问链表的函数定义一下:

Test.cpp(72) : error C2065: 'listlength' : undeclared identifier
Test.cpp(76) : error C2065: 'getelem' : undeclared identifier
Test.cpp(77) : error C2065: 'equal' : undeclared identifier
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-09-27
'getelem' : undeclared identifier getelm没定义
下面那个也是
int locateelem_sq(sqlist l,elemtype e,status(*compare)(elemtype,elemtype))
{
int i=1,*p;
p=l.elem;
while(i<=l.length&&!(*compare)(*p++,e)) ++i;
if(i<=l.length) return i;
else return 0;
}
cannot convert parameter 3 from 'const int' to 'int (__cdecl *)(int,int)'

貌似弄错了 就是说无法将'const int' 转换成'int (__cdecl *)(int,int)'可以直接用参数)(elemtype,elemtype);
相似回答