| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 447 人关注过本帖
标题:一元多项式
只看楼主 加入收藏
绝代双雕
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-10-27
结帖率:0
  已结贴   问题点数:20  回复次数:1   
一元多项式
#include<stdio.h>
#include<stdlib.h>
#include "Status.h"
//typedef  int  LElemType;
//#include"SqList.h"
//typedef SqList mySetType;
typedef  struct polyNode{
    float  coef;
    int  exp;
    struct  polyNode  *next,*prior;
   }*poly;

//typedef  x ElemType;

poly creatSet(int n,float m)
{
    int i;
    poly  pnew,phead,ptail;
    phead=(poly )malloc(sizeof(poly));  //为链表设计一个头结点
    phead->coef=m;
    phead->exp=n;
    phead->next =NULL;
    phead->prior =NULL;
    ptail=phead;
    for(i=0;i<n;i++){
        printf("输入第 %d 个数 :",i+1);
        pnew=(poly )malloc(sizeof(poly));//生成头结点,尾插法
        scanf("%d",& pnew->coef);
        scanf("%d",& pnew->exp);
        ptail->next =pnew ;
        pnew->prior =ptail;   
        ptail=pnew;
        ptail->next =NULL;
    }
    return phead;
}
void  polyAdd(poly  &A,poly  &B)
{   

    poly pa=A->next,pb=B->next,rear=A, q;
    while(pa&&pb){
        if(pa->exp<pb->exp)
        rear->next=pa;
        rear=pa;
        pa=pa->next;
    }
        else if (pa->exp>pb->exp){
        rear->next=pb;
        rear=pb;
        pb=pb->next;
    }
        else{
        pa->coef+=pb->coef;
            if(pa->coef!=0.0){
            rear->next=pa;
            rear=pa;
            pa=pa->next;
            q=pb;
            pb=pb->next;
            free(q);
        }
            else{
            q=pa;
            pa=pa->next;
            free(q);
            q=pb;
            pb=pb->next;
            free(q);
        }
    }
   
}
if(pa)rear->next=pa;
else  rear->next=pb;
 free(B);
}

void main(){
    ploy A,B;
    int n;
    float m;
    scanf("%d",n);
    scanf("%f",m);
    A=creatSet( n,m);
    B=creatSet( n,m);
    polyAdd(  &A, &B);
}
有谁帮着看看这个一元多项式的创建加减呀,我实在不会了
搜索更多相关主题的帖子: include 多项式 
2013-10-27 21:30
yuccn
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:何方
等 级:版主
威 望:167
帖 子:6799
专家分:42379
注 册:2010-12-16
  得分:20 
1 =================
void  polyAdd(poly  &A,poly  &B)
{   

    poly pa=A->next,pb=B->next,rear=A, q;
    while(pa&&pb){
        if(pa->exp<pb->exp)
            rear->next=pa;
        rear=pa;
        pa=pa->next;
    }
        else if (pa->exp>pb->exp){ 这个else if 对应的if在哪里?
            rear->next=pb;
            rear=pb;
            pb=pb->next;
        }
        else{
            pa->coef+=pb->coef;
            if(pa->coef!=0.0){
                rear->next=pa;
                rear=pa;
                pa=pa->next;
                q=pb;
                pb=pb->next;
                free(q);
            }
            else{
                q=pa;
                pa=pa->next;
                free(q);
                q=pb;
                pb=pb->next;
                free(q);
            }
        }

}

2 =================
if(pa)rear->next=pa;
else  rear->next=pb;
free(B);
这块代码是多出来的,楼主是否没有写对括号?
}


3 =================
typedef  struct polyNode{
    float  coef;
    int  exp;
    struct  polyNode  *next,*prior;
}*poly;


void main(){
    ploy A,B;

你看出这两块红的有什么不通吗

我行我乐
我的博客:
http://blog.yuccn. net
2013-10-28 12:01
快速回复:一元多项式
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.072598 second(s), 7 queries.
Copyright©2004-2019, BCCN.NET, All Rights Reserved