回 帖 发 新 帖 刷新版面

主题:小弟弄了一个一元多项式的,有点毛病啊,请各位高人帮忙修正,不胜感激

#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;
}
              

回复列表 (共5个回复)

沙发

我有现成的,要吗?

板凳


上面的兄弟给我发份吧。xuexishijie@126.com

3 楼

兄弟也发个给我吧lone02@163.com

谢谢

4 楼

我也想要份,老大,发给我啊,223103666@qq.com,谢谢

5 楼

就要交作业了,我不想挂课呀!给我一个吧!sardine_tree@126.com

我来回复

您尚未登录,请登录后再回复。点此登录或注册