一元多项式计算

时间:2015-11-07 10:33:10
【文件属性】:

文件名称:一元多项式计算

文件大小:1KB

文件格式:CPP

更新时间:2015-11-07 10:33:10

多项式

#include using namespace std; struct elem { int coef; int exp; elem *next; }; class link { public: link(); link(int a[],int b[],int n); friend void add(link &A,link &B); private: elem *first; }; link::link(int a[],int b[],int n) { elem *r; first=new elem; r=first; for(int i=0;icoef=a[i]; s->exp=b[i]; r->next=s; r=s; } r->next=NULL; } void add(link &A,link &B) { elem *pre,*qer,*q,*p,*v; pre=A.first;p=pre->next; qer=B.first;q=qer->next; while(p!=NULL && q!=NULL) { if(p->expexp){ pre=p; p=p->next; cout<coef<<' '<exp<exp>q->exp){ v=q->next; pre->next=q; q->next=p; q=v; cout<coef<<' '<exp<coef=p->coef+q->coef; cout<coef<<' '<exp<coef==0){ pre->next=p->next; delete p; p=pre->next;} else{ pre=p; p=p->next; } qer->next=q->next; delete q; q=qer->next; } } if(q!=NULL) pre->next=q; delete B.first; } int main() { char m; int a[5],b[5],c[3],d[3]; cin>>m; for(int i=0;i<5;i++) {cin>>a[i]>>b[i];} link A(a,b,5); cin>>m; for(int j=0;j<3;j++) {cin>>c[j]>>d[j];} link B(c,d,3); add( A, B); return 0; }


网友评论