我的加法逻辑有问题吗?帮忙看看
void AddPolyn(Polyn Pa,Polyn Pb){
Polyn ahead,bhead,qa,qb;
float sum;
Polyn temp,temp1;
qa = Pa->next;
qb = Pb->next;
ahead = Pa;
bhead = Pb;
while(ahead->next&&bhead->next)
{
switch(cmp(ahead->expn,bhead->expn))//比较系数大小, <=>返回 -1, 0, 1。
{
case -1:
ahead = qa;
qa = qa->next;
break;
case 0:
sum = ahead->coef + bhead->coef;
if(sum!=0)
{
ahead->coef = sum;
temp = bhead;
bhead = qb;
qb = qb->next;
free(temp);
}
else
{
temp = ahead;
ahead = qa;
qa = qa->next;
free(temp);
temp1 = bhead;
bhead = qb;
qb = qb->next;
free(temp1);
}
break;
case 1:
temp = bhead;
bhead = qb;
qb = qb->next;
ahead = temp;
temp->next = qa;
qa = ahead;
ahead->next = qa;
}
}
if(bhead->next)
{
ahead->next = bhead;
free(bhead);
}
}
Debug Error!
Program:...\myProgram.exe
DAMAGE:after Normal block(#76)at 0x004F2A70.
(Press Retry to debug the application)
终止 重试忽略
不知道怎么回事,还有我的加法逻辑有没有问题哦 。。 这里应该有问题
if(bhead->next)
{
ahead->next = bhead;
free(bhead);
}
当你执行了这句之后,bhead指向的内存已经被释放,但接下来会执行
while(ahead->next && bhead->next)这句,然而bhead已经被释放,所以bhead->next就会出错 楼上正解{:1_1:} 同意2楼,你应该加多个中间值,用来保存bhead
谁能告诉我小甲鱼的数据第43讲为什么不能下载
页:
[1]