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 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序