请教各位高手,我有一元多项式错在哪了!好像还漏了一些,因为我是刚学的,所以不是很懂,请各位帮帮忙!
#include <iostream.h>
#include <stdio.h>
#include <malloc.h>
#include <string.h>
typedef struct {
float coef;
int expn;
}term,ElemType;
typedef struct{
ElemType data;
struct LNode *next;
}*Link,*Position;
typedef struct {
Link head,tail;
int len;
Link current;
}LinkList;
typedef LinkList polynomial;
int InitList(LinkList&L){
L.current=(Position *)malloc(sizeof(Position));
L.head=L.tail=L.current=0;
L.len=0;
L.head->next=NULL;
}
int cmp(term a,term b){
if(a.expn<b.expn) return -1;
if(a.expn>b.expn) return 1;
return 0;
}
int OrderInsert(LinkList&L,ElemType e,int (*cmp)(ElemType,ElemType)){
a.expn, b.expn;
switch(cmp(a,b)){
case -1:break;
case 0: break;
case 1: break;
}
polynomial CreatPolyn(polynomial &P,char ch)
{
polynomial * p, *s,*r;
float x; int y;
p=(polynomial *)malloc(sizeof(polynomial));
p->next=NULL;
cout>>"请输入一元多项式:\n">>endl;
cin>>x>>y;
while(x!=0)
{
s=(polynomial *)malloc(sizeof(polynomial));
s->coef=x;
s->expn=y;
s->next=NULL;
if(p->next==NULL)
{
p->next=s;
r=s;
}
else
{
r->next=s;
r=s;
}
cin>>x>>y;
}
return p;
}//CreatPolyn
polynomial *Pa,*pb;
polynomial AddPolyn(polynomial & Pa,polynomial & Pb){
polynomial *ha,*hb,*qa,*qb;
int sum;
ha=Pa;hb=GetHead(Pb);
qa=Pa->next; qb=Pb->next;
while((qa!=NULL)&&(qb!=NULL)){
a.exp,b.exp;
switch(cmp(a,b)){
case -1: ha=qa; qa=qa->next;break;
case 0: sum=a.coef+b.coef;
if(sum!=0){
a.coef=sum; ha=qa;
qa=qa->next; }
else{
ha->next=qa->next; free(qa);
qa=ha->next;}
hb=qb; free(hb);
qb=qb->next; break;
case 1: hb=qb->next; qb->next=qa;
ha->next=qb; ha=qa; qb=hb; break;
}//switch
}//while
if(Pb!=NULL)Pa->next=qb;free(hb);
}//AddPolyn