zoukankan      html  css  js  c++  java
  • 多项式相乘-数组实现

    多项式抽象数据类型 数组实现的类型声明

    typedef struct
    {
    	int CoeffArray[ MaxDegree + 1 ];
        int HightPower;
    }*Polynomial;
    

    将多项式初始化为零

    void ZeroPolynomial( Polynomial Poly)
    {
        for (int i = 0;i <= MaxDegree; i++)
        	Poly->CoeffArray[i] = 0;
        Poly->HightPower = 0;rr
    }
    

    两个多项式相加

    void AddPolynomial(const Polynomial Poly1,const Polynomial Poly2,const Polynomial PolySum)
    {
    	int i;
        ZeroPolynomial(PoluSum);
        PolySum->HightPower = Max(Poly1->HightPower,Poly2->HightPower);
        for(i = PolySum->HightPower; i >= 0; i--)
        	PolySum->CoeffArray[i] = Poly1->CoeffArray[i] + Poly2->CoeffArray[i];
    }
    

    两个多项式相乘

    void MultPolynomial(const Polynomial Poly1,const Polynomial Poly2 Polynomial PolyProd)
    {
    	int i,j;
        ZeroPolynomial(PolyProd);
        PolyProd->HightPower = Poly1->HightPower + Poly2->HightPower;
        if (PolyProd->HightPower > MaxDegree)
        	Error("Exceeded array size");
        else
        	for(i = 0; i <= Poly1->HightPower; i++)
            	for(j = 0; j <= Poly2->HightPower; j++)
        			PolyPord->CoeffArray[i+j] += Poly1->CoeffArray[i]*Poly2->CoeffArray[j];
    }
  • 相关阅读:
    ymnets----框架内功能了解
    ymnets----代码生成
    关于分层架构
    SQL——抛出错误
    Jump Game
    combination sum && combination sum II
    35-Search Insert Position
    33-Search in Rotated Sorted Array
    34- Find First and Last Position of Element in Sorted Array
    机器学习实战之SVM
  • 原文地址:https://www.cnblogs.com/y3w3l/p/6349640.html
Copyright © 2011-2022 走看看