| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

#include<stdio.h>
#include<stdlib.h>
#include "Status.h"
//typedef  int  LElemType;
//#include"SqList.h"
//typedef SqList mySetType;
typedef  struct polyNode{
float  coef;
int  exp;
struct  polyNode  *next,*prior;
}*poly;

//typedef  x ElemType;

poly creatSet(int n,float m)
{
int i;
for(i=0;i<n;i++){
printf("输入第 %d 个数 :",i+1);
pnew=(poly )malloc(sizeof(poly));//生成头结点，尾插法
scanf("%d",& pnew->coef);
scanf("%d",& pnew->exp);
ptail->next =pnew ;
pnew->prior =ptail;
ptail=pnew;
ptail->next =NULL;
}
}
{

poly pa=A->next,pb=B->next,rear=A, q;
while(pa&&pb){
if(pa->exp<pb->exp)
rear->next=pa;
rear=pa;
pa=pa->next;
}
else if (pa->exp>pb->exp){
rear->next=pb;
rear=pb;
pb=pb->next;
}
else{
pa->coef+=pb->coef;
if(pa->coef!=0.0){
rear->next=pa;
rear=pa;
pa=pa->next;
q=pb;
pb=pb->next;
free(q);
}
else{
q=pa;
pa=pa->next;
free(q);
q=pb;
pb=pb->next;
free(q);
}
}

}
if(pa)rear->next=pa;
else  rear->next=pb;
free(B);
}

void main(){
ploy A,B;
int n;
float m;
scanf("%d",n);
scanf("%f",m);
A=creatSet( n,m);
B=creatSet( n,m);
}

1 =================
{

poly pa=A->next,pb=B->next,rear=A, q;
while(pa&&pb){
if(pa->exp<pb->exp)
rear->next=pa;
rear=pa;
pa=pa->next;
}
else if (pa->exp>pb->exp){ 这个else if 对应的if在哪里？
rear->next=pb;
rear=pb;
pb=pb->next;
}
else{
pa->coef+=pb->coef;
if(pa->coef!=0.0){
rear->next=pa;
rear=pa;
pa=pa->next;
q=pb;
pb=pb->next;
free(q);
}
else{
q=pa;
pa=pa->next;
free(q);
q=pb;
pb=pb->next;
free(q);
}
}

}

2 =================
if(pa)rear->next=pa;
else  rear->next=pb;
free(B);

}

3 =================
typedef  struct polyNode{
float  coef;
int  exp;
struct  polyNode  *next,*prior;
}*poly;

void main(){
ploy A,B;

http://blog.yuccn. net
• 2
• 1/1页
• 1