读书人

2个炼表数据相加。哪错了,该如何解决

发布时间: 2012-03-09 16:54:57 作者: rapoo

2个炼表数据相加。。哪错了
struct num
{
int i;
int j;
struct num *next;
};


for(p1=g1;p1-> next!=NULL;p1=p1-> next)
{
for(p2=g2;p2-> next!=NULL;p2=p2-> next)
{
k=p1-> j;
if(p1-> i==p2-> i)
{
p3-> i=p1-> i;
p3-> j=p1-> j+p2-> j;
t=(struct num*)malloc(sizeof(struct num));
t-> next=NULL;
p3-> next=t;
p3=t;
continue;

}

}
if(p2-> next==NULL&&k==p1-> j)
{
p3-> i=p1-> i;
p3-> j=p1-> j;
}
while(p3-> next!=NULL)
{
printf( "%dx^%d+ ",p3-> j,p3-> i);
}


[解决办法]
在你的程序中,
是否存在这样的 预设条件:
g1 多项式中,最高次方 要高于 g2多项式中的最高次方?

否则,
g2 中的最高次方数据就丢失了 ~

读书人网 >C语言

热点推荐