主题:小弟弄了一个一元多项式的,有点毛病啊,请各位高人帮忙修正,不胜感激
#include <iostream.h>
#include <stdio.h>
#include <ctype.h>
struct polynode
{
int coef;
int exp;
polynode* link;
};
typedef polynode* polypointer;
polypointer attach (int c ,int e,polypointer d)
{
polypointer x;
x=new polynode;
x->coef=c;
x->exp=e;
d->link=x;
return x;
}
char compare(int,int);
polypointer jia(polypointer,polypointer);
polypointer jian(polypointer,polypointer);
polypointer cheng(polypointer,polypointer);
polypointer chu(polypointer,polypointer,polypointer&,polypointer&);
polypointer input(polypointer pointer);
polypointer output(polypointer pointer);
char compare(int,int)
{
int a,b;
char c;
if((a-b)>0)
c='>';
if((a-b)==0)
c='=';
else if ((a-b)<0)
c='<';
return c;
}
polypointer input()
{
int number1,number2;
char c,d,g;
polypointer b,a,e,p,q;
e=new(polynode);
b=new (polynode);
p=e;
q=b;
b->coef=e->coef=0;
b->exp=e->exp=0;
b->link=e->link=NULL;
a=e;
cout<<"输入一个多项式(按指数从高到低排列)"<<endl;
g='+';
while (g!='\n')
{
cin>>number1>>c>>d>>number2;
if (g=='-')
number1=-number1;
if (g=='+')
number1=number1;
b->coef=number1;
b->exp=number2;
a=attach(b->coef ,b->exp ,a);
g=cin.get();
}
a->link=NULL;
e=e->link;
delete p,q;
return e;
}
polypointer output(polypointer a)
{
int number1,number2;
polypointer b;
char g;
if (a==NULL)
{
cout<<"0"<<endl;
}
while (a!=NULL)
{
number1=a->coef;
number2=a->exp;
b=a->link;
if (b!=NULL)
{
if (b->coef>0)
{
g='+';
}
else if (b->coef<0)
{
g='-';
b->coef=-(b->coef);
}
}
else if (b==NULL)
{
g='\n';
}
cout<<number1<<"x^"<<number2<<g<<endl;
a=a->link;
}
return 0;
}
#include <stdio.h>
#include <ctype.h>
struct polynode
{
int coef;
int exp;
polynode* link;
};
typedef polynode* polypointer;
polypointer attach (int c ,int e,polypointer d)
{
polypointer x;
x=new polynode;
x->coef=c;
x->exp=e;
d->link=x;
return x;
}
char compare(int,int);
polypointer jia(polypointer,polypointer);
polypointer jian(polypointer,polypointer);
polypointer cheng(polypointer,polypointer);
polypointer chu(polypointer,polypointer,polypointer&,polypointer&);
polypointer input(polypointer pointer);
polypointer output(polypointer pointer);
char compare(int,int)
{
int a,b;
char c;
if((a-b)>0)
c='>';
if((a-b)==0)
c='=';
else if ((a-b)<0)
c='<';
return c;
}
polypointer input()
{
int number1,number2;
char c,d,g;
polypointer b,a,e,p,q;
e=new(polynode);
b=new (polynode);
p=e;
q=b;
b->coef=e->coef=0;
b->exp=e->exp=0;
b->link=e->link=NULL;
a=e;
cout<<"输入一个多项式(按指数从高到低排列)"<<endl;
g='+';
while (g!='\n')
{
cin>>number1>>c>>d>>number2;
if (g=='-')
number1=-number1;
if (g=='+')
number1=number1;
b->coef=number1;
b->exp=number2;
a=attach(b->coef ,b->exp ,a);
g=cin.get();
}
a->link=NULL;
e=e->link;
delete p,q;
return e;
}
polypointer output(polypointer a)
{
int number1,number2;
polypointer b;
char g;
if (a==NULL)
{
cout<<"0"<<endl;
}
while (a!=NULL)
{
number1=a->coef;
number2=a->exp;
b=a->link;
if (b!=NULL)
{
if (b->coef>0)
{
g='+';
}
else if (b->coef<0)
{
g='-';
b->coef=-(b->coef);
}
}
else if (b==NULL)
{
g='\n';
}
cout<<number1<<"x^"<<number2<<g<<endl;
a=a->link;
}
return 0;
}