|
>next;
}
else
{
if(pa->exp+pb->expnext;
else
pa=pa->next; //大于k 减小pa
}
}
if(ceof!=0.0) //有系数了 就将此节点插入到c链表中
{
if(NULL==(newnode=(listnode *)malloc(sizeof(listnode))))
{
printf("链表C节点开辟失败");
exit(-1);
}
newnode->coef=ceof;
newnode->exp=k;
newnode->next=NULL; //插入节点数据
pc->next=newnode;
pc=newnode; //插入节点
ceof=0.0;
}
}
InverseList(head_b);
return head_c;
}
int InverseList(listnode *head) //逆置链表
{
listnode *p=head->next,*q; //p指向正要逆置的节点,q指向下一个待逆置的节点
head->next=NULL;
while(p) //当前节点不为空
{
q=p->next;//保存下一个节点
p->next=head->next; //先更新逆置点的 next
head->next=p; //在更新head->next
p=q; //下一轮
}
return 0;
}
|