指针函数的调用与返回
程序报错为:cannot convert parameter 1 from 'struct stu' to 'struct stu *'我定义的sa、Hc、hc都为同一类型的啊
不知道错在哪
知道的请指点下
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#define NULL 0
#define SIZ sizeof(struct stu)
struct stu
{
int num;
stu *next;
};
stu *r,*s;
void main()
{
stu * same(stu *ha,stu *hb);
stu *Ha = NULL; stu *Hb = NULL; stu *Hc = NULL; //定义头指针
int x;
cout << "in put A:" << endl; //建立单链表A
cin >> x;
r = Ha;
for(; x ;cin >> x)
{
s = (stu*) malloc(SIZ);
s->num = x;
if(Ha == NULL)
Ha = s;
else
r->next = s;
r = s;
}
if(r != NULL)
r->next = NULL;
r = Ha;
while(r != NULL)
{
cout << r->num <<" ";
r = r->next;
}
cout << endl;
cout << "in put B:" << endl; //建立单链表B
cin >> x;
r = Hb;
for(; x ; cin>>x)
{
s = (stu*)malloc(SIZ);
s->num = x;
if(Hb == NULL)
Hb = s;
else
r->next = s;
r = s;
}
if(r != NULL)
r->next = NULL;
r = Hb;
while(r != NULL)
{
cout << r->num <<" ";
r = r->next;
}
cout << endl;
Hc = same( *Ha, *Hb);
r = Hc;
while(r != NULL)
{
cout << r->num <<" ";
r = r->next ;
}
free(s);
}
stu *same(stu *ha,stu *hb)
{
stu *hc = NULL;
r = hc;
stu *q = ha;
stu *p = hb;
s = (stu*)malloc(SIZ);
while(p != NULL && q != NULL) //值相同时,插入c中
{
if(p->num = q->num)
{
s->num = p->num ;
if(hc == NULL)
{
hc = s;
}
else
{
r->next = s;
r = s;
}
s = (stu*)malloc(SIZ);
p = p->next ;
q = q->next ;
}
else
{
if(p->num < q->num )
{
p = p->next ;
}
else
{
q = q->next ;
}
}
}
if(r != NULL)
r->next = NULL;
return hc;
}