书中代码:
void union(List *La,List Lb)
{
int La_len,Lb,_len,i;
ElemType e;
La_len=ListLenth(La);
Lb_len=ListLenth(Lb);
for(i=1;i<=Lb_len;i++)
{
GetElem(Lb,i,e);
if(!LocateElem(La,e,equal))
ListInsert(La,++La_len,e);
}
}
List是类型名吗?
为什么La是指针的形式,Lb却不是?
书中ListLenth函数的原型是ListLenth(L)
但本函数中调用的时候,传入的参数既有*La(指针),又有Lb(非指针),何解?
看你List怎么定义的
如果 typedef struct
{
Node * next;
ElemType value;
} * List;
那么List就是指针,没毛病。
否则就不是指针。
如果List是指针,那么List * 就是指针的指针(如果list不是指针,那么list *是指针)。那么在函数里使用 List *la 的动机就是,这个函数需要修改la的指向,让它指向另一个List
并且结果作用到函数调用者上。