njustyf 2016-03-25 13:24 采纳率: 16.7%
浏览 1921

数据结构一元多项式相乘问题

这两个错误是什么问题,求告知
[Error] a function-definition is not allowed here before '{' token
[Error] expected '}' at end of input

  • 写回答

3条回答

  • njustyf 2016-03-25 13:28
    关注

    #include using namespace std;struct Node{float coef; //系数int exp; //指数Node next;};class LinkList{private: Node*head;public:LinkList( ); LinkList(int n); ~LinkList( ); void PrintList( ); void Sort(LinkList A);void Add(LinkList &A,LinkList B);void Mul(LinkList&A,LinkList B);void PloyMul();void ExitSystem();void Menu();};LinkList::LinkList(){ head=new Node; head->next=NULL;}LinkList::LinkList(int n){ head=new Node; head->next=NULL; Node*p,*r; for(int i=0;i>p->coef>>p->exp; p->next=r->next; r->next=p;}}LinkList::~LinkList(){ Node*p=head->next; while(p){ head->next=p->next; delete p; p=head->next; } delete head;} void LinkList::PrintList(){Node*p=head->next;if(p->coef>0){ if(p->coef==1){ if(p->exp==1) cout<<"X";elsecout<<"X"<exp; } else{ if(p->exp==1) cout<coef<<"X"; else cout<coef<<"X"<exp; } }else if(p->coef==0){ } else { if(p->coef==-1){ if(p->exp==1) cout<<"-X"; else cout<<"-X"<exp; } else { if(p->exp==1) cout<coef<<"X"; else cout<coef<<"X"<exp; } p=p->next; while(p!=NULL){ }if(p->coef>0){ if(p->coef==1){ if(p->exp==1) cout<<"+X";elsecout<<"+X"<exp; } if(p->coef!=1){ if(p->exp==1) cout<<"+"<coef<<"X"; else cout<<"+"<coef<<"X"<exp; } }if(p->coef==0){ }if(p->coefcoef==-1){ if(p->exp==1) cout<<"-X"; else cout<<"-X"<exp; } if(p->coef!=-1){ if(p->exp==1) cout<coef<<"X"; else cout<coef<<"X"<exp; } p=p->next;}}void LinkList:: Sort(LinkList A) {Node*p=head->next,*q,*maxp;int temp1,twmp2;while(p->exp){ maxp=p,q=p->next; while(p){ if(maxp->expexp)maxp=q; q=q->next; } temp1=p->exp; p->exp=maxp->exp; maxp->exp=temp1; temp=p->coef; p->coef=map->coef; maxp->coef=temp2; p=p->next;}}void LinkList::Add(LinkList &A,LinkList B){ Node*pr,*qr,*p,*q,*v;pr=A.head;p=pr->next;qr=B.head;q=qr->next;while(p!=NULL&&q!=NULL){ if(p->expexp){ pr=p; p=p->next; } else if(p->exp>q->exp){ v=q->next; pr->next=q; q->next=p; q=v; } else { p->coef=p->coef+q->coef; if(p->coef==0){ pr->next=p->next; pr=p; delete p; p=pr->next; } else{ pr=p; p=p->next; } qr->next=q->next; qr=q; delete q; q=qr->next; } if(q!=NULL){ pr->next=q; delete B.head; }}} void LinkList:: Mul(LinkList&A,LinkList B){LinkList D;Node*pr,*qr,*p,*q,*rr,*r;pr=A.head;p=pr->next;qr=B.head;q=qr->next;while(q!=NULL){ LinkList C; rr=C.head; r=rr; while(p!=NULL) { Node*s; s=new Node; s->coef=(p->coef)(q->coef); s-exp=p->exp+q-exp; r=s; r->next=Null; pr=p; p=p->next; } Add(D,C); qr=q; q=q->next; p=pr->next;}if(q==NULL){Sort(D);D.PrintList();} else{ cout<<"error!"<>n1; LinkList A(n1); Sort(A); cout<<"输入第二个多项式的项数:"<>n2; LinkList B(n2); Sort(B); cout<<"相乘后结果:"; Mul(A,B); cout<<"\n是否继续" }}void LinkList::ExitSystem(){ exixt(1);}void LinkList::Menu(){ while(true){ char sign; cout<<"\n\n"; cout<<"1.chengfa"; cout<<"2.tuichu"; cout<<""; cin>>sign; switch(sign) {case'1':PloyMul(); break; case'2':ExitSystem(); break; default:break; } cin.sync(); system("cls"); }}int main(){ Menu(); return 0;}

    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧